我正在尝试使用Oracle Sql Loader实用程序将一些数据加载到Oracle DB中,但是我在TERMINATED和ENCLOSED字段后找到了没有终结符的字段'以下情况的例外情况:
我的sqlldr控制文件是:
load data
append
into table fp_metadata
fields terminated by "|" optionally enclosed by '"'
TRAILING NULLCOLS
(
TABLE_NAME CHAR(30),
FIELD_NAME CHAR(60),
CURINDICATOR FLOAT,
SPLITINDICATOR CHAR(4),
UNITFACTOR FLOAT,
DESCRIPTION CHAR(450)
)
错误是:
Column Name Position Len Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
TABLE_NAME FIRST 30 | O(") CHARACTER
FIELD_NAME NEXT 60 | O(") CHARACTER
CURINDICATOR NEXT 4 FLOAT
SPLITINDICATOR NEXT 4 | O(") CHARACTER
UNITFACTOR NEXT 4 FLOAT
SQL string for column : "NVL(:UNITFACTOR,NULL)"
DESCRIPTION NEXT 450 | O(") CHARACTER
value used for ROWS parameter changed from 100000 to 65534
Record 16: Rejected - Error on table FP_METADATA, column SPLITINDICATOR.
no terminator found after TERMINATED and ENCLOSED field
错误记录是:
"a"|"zzz"|0|""||"test0"
"b"|"xxx"|0|""||"test1"
"c"|"yyy"|1|"P"|1|"test2" <--! here sqlldr has been failing
UPD:
errorneus输入行的另一个例子是:
"fp_basic_bd"|"p_price"|1|"P"|1|"Price - Closing"
请你指出我的错误吗?
答案 0 :(得分:2)
只是猜测您的错误,但请尝试删除数据中的双引号或使用2个双引号更改1双引号。您可以在控制文件本身中执行此操作。尝试(未经测试):
LOAD DATA
...
(
...
splitindicator nullif splitindicator = blanks "replace(:splitindicator, '"', '""')"
...
)
您应该可以使用以下方法删除双引号:
splitindicator nullif splitindicator = blanks "replace(:splitindicator, '"', '')"
如果这不起作用,您可能需要修复数据文件本身(或者如果数据源来自其他SQL,则使用提取时的替换函数)
希望有效
答案 1 :(得分:1)
我找到了一个解决方案,要求您稍微更新控制文件,以指定&#34;由&#34;每个字段的字符,而不是所有字段的字符。
对于我的情况,我有一个问题,如果[first_name]字段带有双引号包装昵称,它将无法加载。 (EG:Jonathon&#34; Jon&#34;)。在数据文件中,名称显示为&#34; Jonathon&#34; Jon&#34;&#34; 。因此&#34;包含在&#34;抛出一个错误是因为值周围有双引号,而且部分值附近有双引号(&#34; Jon&#34;)。因此,我没有指定该值应该用双引号括起来,而是省略了它,只是手动删除了字符串中的引号。
Load Data
APPEND
INTO TABLE MyDataTable
fields terminated by "," ---- Noticed i omitted the "enclosed by"
TRAILING NULLCOLS
(
column1 enclosed by '"', --- Specified "enclosed by" here for all cols
column2 enclosed by '"',
FIRST_NAME "replace(substr(:FIRST_NAME,2, length(:FIRST_NAME)-2), chr(34) || chr(34), chr(34))", -- Omitted "enclosed by". substr removes doublequotes, replace fixes double quotes showing up twice. chr(34) is charcode for doublequote
column4 enclosed by '"',
column5 enclosed by '"'
)