1、表結構
create table t_student(
id number(10) primary key,
name varchar2(50),
birthday date
); create sequence seq_t_student start with 1 increment by 1; insert into t_student values(seq_t_student.nextval,'張三',sysdate);
insert into t_student values(seq_t_student.nextval,'李四',to_date('1990-01-01 13:13:13','yyyy-mm-dd hh24:mi:ss'));
commit;
2、shell
#!/bin/bash
sqlplus -s centos/centos@win7orcl <<EOF >/ljxd/shell-demo/oracle/student.txt
set pages 0
set feed off
set heading off
set feedback off
set verify off
set linesize 1000
select t.id||'###'||t.name||'###'||to_char(t.birthday,'yyyy-mm-dd hh24:mi:ss') from t_student t;
EOF
3、分析
centos/centos@win7orcl #資料庫客戶端配置請參考http://www.cnblogs.com/crazyMyWay/articles/4371984.html
/ljxd/shell-demo/oracle/student.txt #為輸出的檔案
set pages 0 #從txt文字第一行開始寫入
set feed off #...
set heading off #去掉表頭寫入
set feedback off #去掉最後一行空白行寫入
set verify off #...
set linesize 1000 #每行只能1000個字元
4、測試命令
5、匯出的結果檔案如下: