在将数据加载到数据库时,Sqlloader会错过双引号

时间:2016-10-02 16:21:27

标签: oracle sql-loader

我有文本文件,并尝试加载到oracle数据库,它能够成功加载到oracle数据库。无论何时加载到oracle数据库,它都会忽略双引号("),它在大约双引号内。

Current sql loader status

input file: 
 "A",165,"TAKE ONE IN THE MORNING (ROUND BLUE TABLET, MARKED ""LT"")"
 output file: 
 "A",165,"TAKE ONE IN THE MORNING (ROUND BLUE TABLET, MARKED "LT")"

Expected output sql loader status

input file: 
 "A",165,"TAKE ONE IN THE MORNING (ROUND BLUE TABLET, MARKED ""LT"")"
 output file: 
 "A",165,"TAKE ONE IN THE MORNING (ROUND BLUE TABLET, MARKED ""LT"")"

Control file :-

load data
CHARACTERSET UTF8
into table TK_000153_2016052029235
fields terminated by "," optionally enclosed by '"' TRAILING NULLCOLS
(Status,Code,Comment)

Table status :-

   Status   Code  Comment
    A       165   TAKE ONE IN THE MORNING (ROUND BLUE TABLET, MARKED "LT")

1 个答案:

答案 0 :(得分:1)

我的理解是你想在保留双引号的同时将数据加载到表中。由于分隔符是逗号,并且注释字段可以包含逗号,因此您需要使用optionally enclosed by '"'子句,其副作用不仅是从整个注释中删除周围的双引号,还会导致sqlldr将评论中的连续双引号解释为"引用"双引号并将它们减少为一个。如果这些假设是正确的,请继续阅读。

对于状态等字段,字段不包含逗号,请使控制文件通过重新连接来添加双引号。请注意,您需要从sqlldr中删除它们。

对于评论字段,它有点棘手,因为您还需要替换单个双引号(在评论内部,这将是因为它们的行为已经减少到一个在将双引号加到每一端之前,可选择用子句括起来,并带有2个双引号。

load data
CHARACTERSET UTF8
into table TK_000153_2016052029235
fields terminated by "," optionally enclosed by '"' TRAILING NULLCOLS
( Status " '\"' || :Status || '\"' "
 ,Code
 ,Comment " '\"' || replace(:Comment , '\"', '\"\"') || '\"' "
)

这有点难看,但我相信如果我理解你想要做什么就会在保持双引号的同时加载数据,同时保持它在你处理的sqlldr部分。

嗯,从技术上讲,你并不是真的"保持"双引号,但在&#34之后将它们添加回你想要的地方;可选地用"子句删除它们。