用sqldlr怎么导入dat文件到ORACLE数据库不同的表中
在一个dat文件中有很多行,但不是都导入到同一个表中,根据他们的第二列的值来判断导入到哪张表里
:
35|20|IsXhZknLJbWgQsfvw|8250102556485617|99666611100059963|20110728165416
271|20|IsXhZknLJbWgQsfvw|8250102584439347|99666611230068775|20110728165433
54|9|UvleUBhZUNzbbgVbD|8250102372401749|99666610510057790|2011.07.28 16:54:53|0|8|20110728165444
259|10|RqMkMldmWnpOnugYu|8250102786758403|99666611190067255|2011.07.28 16:55:07|KeyPress|3|20110728165458
像这样的数据 根据第二列的数据 如 20, 9, 10 这三个值来把这四条数据插入到a,b,c 三 张表里
------解决方案--------------------可以实现的,加when 条件判断,sqlldr有这个用法。
------解决方案--------------------加上when的语法如下:
LOAD DATA
INFILE *
INTO TABLE DEPT
REPLACE
FIELDS TERMINATED BY ','
TRAILING NULLCOLS
(DEPTNO,
DNAME "upper(:dname)",
LOC "upper(:loc)",
LAST_UPDATED
"case
when length(:last_updated) > 9
then to_date(:last_updated,'hh24:mi:ss dd/mm/yyyy')
when instr(:last_updated,':') > 0
then to_date(:last_updated,'hh24:mi:ss')
else to_date(:last_updated,'dd/mm/yyyy')
end"
)
你可以参考下
------解决方案--------------------可以使用when判断,b表和c表中第一个字段必须有position(1)重置
load data
infile 'file.dat'
truncate
into table a
when col2='20'
fields terminated by '|'
trailing nullcols
(col1, col2, ...)
into table b
when col2='9'
fields terminated by '|'
trailing nullcols
(
col1 position(1),
col2,
...
)
into table c
when col2='10'
fields terminated by '|'
trailing nullcols
(
col1 position(1),
col2,
...
)
------解决方案--------------------LOAD DATA
INFILE 'x.txt'
APPEND INTO TABLE A
WHEN A_COL2 = '20'
FIELDS TERMINATED BY "|" OPTIONALLY ENCLOSED BY " " TRAILING NULLCOLS
( A_COL1 "TRIM(:A_COL1)",
A_COL2 "TRIM(:A_COL2)",
...
)
INTO TABLE B
WHEN B_COL2 = '9'
FIELDS TERMINATED BY "|" OPTIONALLY ENCLOSED BY " " TRAILING NULLCOLS
( B_COL1 "TRIM(:B_COL1)",
B_COL2 "TRIM(:B_COL2)",
...
)
....