1、输出txt文件(用于sqlldr导入)
SPOOL test.txt
select id|| '|' || name FROM test ;
SPOOL OFF
SQLLOAD导入数据:
sqlldr 'dbname/dbpassword'@数据库ip_实例 control=test.ctl ERRORS=10000 rows=1000 direct=y
2、导出sql文件(用于insert批量插入)
SPOOL INSERT.sql
select 'insert into test(id,name ) values(''' || id || ''',''' || name||''');'
FROM test;
select 'commit;' from dual;
select 'exit;' from dual;
SPOOL OFF
INSERT导入数据:
sqlplus 'dbname/dbpassword'@数据库ip_实例 @INSERT.sql > test.log
3、输出到csv文件
set echo off
set feedback off
set newpage none
set verify off
set pagesize 0
set term off
set trims on
set linesize 2000
set heading off
set timing off
set numwidth 38
SPOOL test.csv
select '证件号,姓名,年龄' from dual;
select a.id|| ',' || a.name|| ',' || a.age FROM test a ;
SPOOL OFF