之前项目有用到的一些导入和导出,时至已久整理一下,做个记号
导入文件:
1. 在某路径下写控制文件 e:/testRegionControl.ctl :
load data
infile e:/region.txt
truncate into table region
fields terminated by X'09'
TRAILING NULLCOLS
(
PPCC_ID :PPCC_ID),
PPCC_PRINT_CODE :PPCC_PRINT_CODE,
PPCC_STATUS :PPCC_STATUS,
PPCC_STATUS :PPCC_STATUS,
filler1 FILLER,
PPCC_MPDC_CREATE_DATE to_date('" + PPCC_MPDC_CREATE_DATE + "','YYYY-MM-DD'),
PPCC_MPDC_UPDATE_POINT_FLAG constant '1',
PPCC_MPDC_AMT to_number(trim(:PPCC_MPDC_AMT))
)
2. 用SQLldr命令导入数据:
sqlldr silent=header feedback discards partitions userid=shawn/shawn@DEMO control=e:/testRegionControl.ctl log=e:/testRegionControl.log bad=e:/testRegionControl.bad
用expdp 导出,前提是directory已经它所指向的路径存在:
expdp shawn/shawn@DEMO directory=TEST_DIRECTORY dumpfile=test.dmp logfile=test.log
用exp 导出
exp shawn/shawn@DEMO file=D:/test1.dmp tables=(region)
exp shawn/shawn@DEMO file=D:/test2.dmp tables=(emp,dept)
用Spool 导出数据到文本:
1. 首先编辑文件 test_sqlldr_exp.sql:
**********************************************
set trimspool on
set linesize 120
set pagesize 2000
set newpage 1
set heading off
set term off
spool e:/Others/sp_test.txt
select * from region;
spool off
/
**********************************************
或者
**********************************************
set wrap off
set linesize 100
set feedback off
set pagesize 0
set verify off
set termout off
set lines 1024 trimo on trimspo on
set echo off
spool e:/Others/sp_test.txt
select * from dual where dual.dummy = null
/
select * from region;
/
spool off
exit
**********************************************
2. 然后用sqlplus 命令来执行这个文件
sqlplus -s shawn/shawn@Demo @test_sqlldr_exp.sql