如何在 sql 加载程序中调用控制文件中的 ora_hash 函数?

How to call ora_hash function inside control file in sql loader?

我正在尝试调用 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
                       ^                    

任何想法

你做错了几件事。直接错误是因为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:

The following requirements and restrictions apply when you are using SQL strings:

  • ...
  • The SQL string must be enclosed in double quotation marks.

To refer to fields in the record, precede the field name with a colon (:). Field values from the current record are substituted. A field name preceded by a colon (:) in a SQL string is also referred to as a bind variable. Note that bind variables enclosed in single quotation marks are treated as text literals, not as bind variables.

您可以考虑在要加载数据的 table 上使用虚拟列。

对于确定性地基于同一行中其他列值的列,通常最终会成为比涉及 SQL*Loader.

的任何解决方案更简单的解决方案