一个简单控制文件的编写:
--fields terminated by ',' enclosed by '"' ---如果数据的所有终止符号一样,设置默认终止符:whitespace(空格、tab、换行、换页、回车)/'string'
--badfile ---是指给的外部文件中不符合终止要求,不入库的数据
--discardfile---是指由when条件过滤掉的数据
--replace(先做delete,然后插入新行)、append(追加新行)、truncate(删除数据,然后替换)、insert
--when ---条件过滤
--trailing nullcols ---数据文件中没有,但是控制文件中有的列,这些列通过该语句置null
--nullif 条件、defaultif 条件
--begindata ---数据在控制文件中
--filler:过滤字段,不必在表中出现,主要用于when条件过滤,注意filler在position关键字前边
--注意:sqlloader读取平面文件中的数据是按照行读取的,即便是到下张表,也一直是按照行来读取的,所以position应用就急为重要在多表加载中
Options(direct=ture)
Load data
infile 'D:\sqlloader\b.csv' badfile 'D:\sqlloader\b.bad' discardfile 'D:\sqlloader\b.dsc'
Append
into table a1
when rowsid='1'
trailing nullcols
(
rowsid filler char terminated by ',',
sex char terminated by ',',
Name char terminated by ',')
into table a2
when rowsid='2'
trailing nullcols
(
rowsid filler position(1) char terminated by ',',
sex1 char terminated by ',',
Name1 char terminated by ','
)
into table a3
when rowsid='3'
trailing nullcols
(
rowsid filler position(1) char terminated by ',',
sex char terminated by ',',
Name char terminated by ','
)
------------------------------------------------------------------------------------
The POSITION parameter in the second INTO TABLE clause is necessary to load this data correctly.
It causes field scanning to start over at column 1 when checking for data that matches the second format.
Without it, SQL*Loader would look for the recid field after dname.(摘之Oracle联机文档)
------------------------------------------------------------------------------------
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23890223/viewspace-1081285/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/23890223/viewspace-1081285/