基礎知識整理

sql loader

1.如果所給是一個excel,直接另存爲csv格式

2.分隔符不是逗號,可以在控制文件中用fields terminated by的值修改


導入文件,需要有控制文件和數據文件
控制文件內容:
load data
infile data.dat
truncate into table t_simtype
fields terminated by "," optionally enclosed by '"'
(ENAME,JOB,SAL)

數據文件存儲按照控制文件中的說明格式的數據

運行sqlldr:
sqlldr  xxxx/xxxx  control=xxxx(控制文件名)

若沒有分隔符,可以指定字符串範圍
如:
load data
infile xxx.dat
truncate into table xxxx

ename position(1:5),
job position(7:15),
sal position(17:20)

可以用position(*+2:15)  *表示上一個字段的結束位置

3.數據文件中的列比要導入到表中的少
load data
infile xxx.dat
truncate into table xxxx
(
ename position(1:5),
job position(7:15),
sal "0"
comm "substr(:sal,1,1)"
)

4.數據文件中有多餘列
(1)定長的
load data
infile xxx.dat
truncate into table xxxx
(
ename position(1:6)
tcol filler position(8:11)
job position(13:21)
)
(2)非定長
load data
infile xxx.dat
truncate into table xxxx
fields terminated by ","
(ename,tcol filler,job,sal)

4.多個數據文件導入同一張表
load data
infile xxx1.dat
infile xxx2.dat
truncate into table xxxx
fields terminated by ","
(mgrno,mname,job)

5.同一個數據文件,導入不同的表
load data
infile xx.dat
discardfile xxx.dat
truncate
  into table xxxx
 when tab='bon'
 (tab filler position(1:3),
 ename position(5:9),
 job position(*+1:18)
 )
 into table xxxx1
 when tab='mgr'
 (tab filler position(1:3),
 mgrno position(4:5),
 mname position(7:13)
)

6.對導入數據做修改
僅適用於常規導入
load  data
infile xx/xx
into table xxxx
(
rec_no "my_db_sequenct.nextval",
region CONSTANT '31',
time_loaded "to_Char(sysdate,'hh24:MI')",
data1 position(1:5) ":data/100"
data2 position(6:15) "upper(:data2)",
data3 position(16:22) "to_date(:data3,'YYMMDD')"
)

 

 

跳過指定行數
load data
infile xxx/xxx
into table xxx
skip 5(跳過前五行)

data1 position(1:5)
data2 position(6:15)

 

7.文件的導出
可使用如下語句
set echo off newpage 0  space 0 pagesize 0 feed off head off trimspool on spool oradata.txt
select col1 || ',' || col2 || ',' || col3 from tab1
where col2='xyz';
spool off

 

when中只支持and,不支持or

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章