我有一个通过sql查询动态创建CTL文件的进程。我必须将文件名插入到oracle表中。我能够获得在查询上显示的文件名,但它一直拒绝它。 ctls只接受数字吗?因为如果我将它硬编码为数字,它将起作用。如果我硬编码到varchar,它将拒绝它。如何在加载时插入文件名?
' LEAD_TIME,' || chr (10) ||
' DELIVERY_TIME,' || chr (10) ||
' DELIVERY_NO,' || chr (10) ||
' FREQUENCY,' || chr (10) ||
' FREQUENCY_UNIT,' || chr (10) ||
' MODE_TYPE,' || chr (10) ||
' AUDIT_LOG_ID "' || MAX(audit_log_id) || '",' || chr (10) ||
' STAGING_STATUS_ID "1",' || chr (10) ||
' FILENAME "&fname",' || chr (10) ||
' LINENO SEQUENCE(1)' || chr (10) ||
' )' || chr (10)
from audit_log
where filename_orig = '&fname';
spool off
这是运行sqlldr的输出。它正确显示文件名,但仍拒绝该条目。
Column Name Position Len Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
VENDOR FIRST * , CHARACTER
COMM_CONTRACT NEXT * , CHARACTER
SERV_CONTRACT NEXT * , CHARACTER
ADDR_CHAIN NEXT * , CHARACTER
STORE NEXT * , CHARACTER
SITE_GROUP NEXT * , CHARACTER
START_DATE NEXT * , CHARACTER
END_DATE NEXT * , CHARACTER
ORDER_DAY NEXT * , CHARACTER
ORDER_TIME NEXT * , CHARACTER
LEAD_TIME NEXT * , CHARACTER
DELIVERY_TIME NEXT * , CHARACTER
DELIVERY_NO NEXT * , CHARACTER
FREQUENCY NEXT * , CHARACTER
FREQUENCY_UNIT NEXT * , CHARACTER
MODE_TYPE NEXT * , CHARACTER
AUDIT_LOG_ID NEXT * , CHARACTER
SQL string for column : "26004459"
STAGING_STATUS_ID NEXT * , CHARACTER
SQL string for column : "1"
FILENAME NEXT * , CHARACTER
SQL string for column : "filenamexxx.csv"
LINENO SEQUENCE (1, 1)
value used for ROWS parameter changed from 64 to 51
Table DISA_STAGING_SUPP_SCHEDULE:
0 Rows successfully loaded.
6 Rows not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.
0 Rows not loaded because all fields were null.
答案 0 :(得分:1)
您应该看到ORA-00984: column not allowed here
之类的错误。 filenamexxx.csv
被视为列名而不是值,因为它没有引用;您可以将其更改为:
FILENAME "'filenamexxx.csv'"
要做到这一点,你的查询已经转换了替换变量周围的单引号:
' FILENAME "''&fname"'',' || chr (10) ||
或者如果您愿意,可以选择引用机制:
q'[ FILENAME "'&fname"',]' || chr (10) ||