我试图在sqlldr中调用一个函数(ORA_HASH),但是我无法实现目标。
数据文件
abc.txt
AKY,90035,"G","DP",20150121,"",0,,,,,,"","E8BD4346-A174-468B-ABC2-1586B81A8267",1,17934,5099627512855,"TEST of CLOROM","",14.00,"",14.00,17934,5099627512855,"TEST of CLOROM",14.00,"ONE TO BE T ONE",344,0,"98027f93-4f1a-44b2-b609-7ffbb041a375",,,AKY8035,"Taken Test","L-20 Shiv Lok"
AKY,8035,"D","DP",20150121,"",0,,,,,,"","E8BD4346-A174-468B-ABC2-1586B81A8267",2,17162,5099627885843,"CEN TESt","",15.00,"",250.00,17162,5099627885843,"CEN TESt",15.00,"ONE TDAILY",3659,0,"09615cc8-77c9-4781-b51f-d44ec85bbe54",,,LLY8035,"Taken Test","L-20 Shiv Lok"
控制文件
cnt_file.ctl
load data
into table Table_XYZ
fields terminated by "," optionally enclosed by '"'
F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12,F13,F14,F15,F16,F17,F18,F19,F20,F21,F22,F23,F24,F25,F26,F27,F28,F29,F30,F31 ORA_HASH(CONCAT(F2,F5,F6,F9,F10,F12,F13,F14,F15,F16,F17,F19,F21,F22)),F32 ORA_HASH(CONCAT(f23,H24,F7,F8,F3)),F33,F34,F35
sqlldr "xxxxx/yyyyy" control=cnt_file.ctl data=abc.txt
每当我从Linux框执行sqlldr时,我都会遇到错误
SQL*Loader-350: Syntax error at line 4.
Expecting "," or ")", found "ORA_HASH".
F29,F30,F31,KEY_CLMNS_HASH ORA_HASH(CONCAT( F2,F5
^
任何想法
答案 0 :(得分:1)
您可以考虑在要加载数据的表上使用虚拟列。
对于确定性地基于同一行中其他列值的列,这通常最终会比涉及SQL * Loader的任何内容更简单。
答案 1 :(得分:0)
你做错了一些事。立即错误是因为Oracle函数调用必须用双引号括起来:
...,F31 "ORA_HASH(CONCAT(F2,F5,F6,...))",...
第二个问题是concat函数只接受两个参数,所以你要么必须嵌套(很多)concat调用,要么更可读地使用连接运算符:
...,F31 "ORA_HASH(F2||F5||F6||...)",...
最后,您需要在函数调用中使用冒号前缀:
...,F31 "ORA_HASH(:F2||:F5||:F6||...)",...
这解释为in the documentation:
使用SQL字符串时,以下要求和限制适用:
- ...
- SQL字符串必须用双引号括起来。
和
要引用记录中的字段,请在字段名称前面加冒号(:)。来自当前记录的字段值被替换。 SQL字符串中以冒号(:)开头的字段名称也称为绑定变量。请注意,用单引号括起来的绑定变量被视为文本文字,而不是绑定变量。