天天看點

基礎知識整理

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(控制檔案名)

若沒有分隔符,可以指定字元串範圍

如:

infile xxx.dat

truncate into table xxxx

ename position(1:5),

job position(7:15),

sal position(17:20)

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

3.資料檔案中的列比要導入到表中的少

(

sal "0"

comm "substr(:sal,1,1)"

)

4.資料檔案中有多餘列

(1)定長的

ename position(1:6)

tcol filler position(8:11)

job position(13:21)

(2)非定長

fields terminated by ","

(ename,tcol filler,job,sal)

4.多個資料檔案導入同一張表

infile xxx1.dat

infile xxx2.dat

(mgrno,mname,job)

5.同一個資料檔案,導入不同的表

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'

 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')"

跳過指定行數

infile xxx/xxx

into table xxx

skip 5(跳過前五行)

data1 position(1:5)

data2 position(6:15)