问题是当我在NAME列中放入两个以上的双引号(检查下面的代码)然后sqlldr失败。在data.txt文件中,前3条记录失败,因为NAME列(记录中的第2个位置)有两个以上的双引号。请协助。我认为我需要将一些函数放在NAME列的控制文件中。
您可以运行以下代码并检查,前3条记录将失败,最后一条记录将被插入,我想插入所有带或不带双引号的记录:
--table creation
create table employee
(
name varchar2(4000)
);
--control file
load data
infile '/tmp/swetabh/data.txt'
into table employee
truncate
fields terminated by "," OPTIONALLY ENCLOSED by '"' TRAILING NULLCOLS
(
name
)
--data.txt (SEE ALL RECORDS ARE HAVING MORE THAN 2 DOUBLE QUOTE AND WANT TO INSERT DATA TO THE TABLE WITH OR WITHOUT DOUBLE QUOTE)
""start with double quote "
"end with double quote ""
"double quote " in the middle "
-bash-4.1 $ sqlldr userid = xxx / xxx @ xxxx control = / tmp / swetabh / control.txt log = / tmp / swetabh / control.log bad = / tmp / swetabh / bad.txt readsize = 2000000000 bindsize = 2000000000
您是否可以控制流程的提取部分?如果是这样,你可以指定数据中的双引号加倍(引用)吗?或者甚至更好,指定使用管道作为分隔符,没有周围的双引号。
如何应用REPLACE
函数将取代双引号(CHR(34)
)什么都没有(NULL
)?另外,删除OPTIONALLY ENCLOSED
条款。
控制文件:
load data
infile *
replace
into table employee
fields terminated by "," TRAILING NULLCOLS
(
name "replace(:name, chr(34), null)"
)
begindata
""start with double quote "
"end with double quote ""
"double quote " in the middle "
测试:
SQL> $sqlldr scott/tiger control=test04.ctl log=test04.log
SQL*Loader: Release 11.2.0.2.0 - Production on Uto O×u 19 19:14:49 2019
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 2
Commit point reached - logical record count 3
SQL> select * From employee;
NAME
--------------------------------------------------
start with double quote
end with double quote
double quote in the middle
SQL>