ORA-00936: SQL*LOADER 控制文件中缺少表达式

ORA-00936: missing expression in SQL*LOADER control file

我有一个 control.ctl 文件,我正在使用 SQL*LOADER 将此数据加载到 table.

LOAD DATA
INFILE 'data_for_insert.csv'
INSERT INTO TABLE TABLE_NAME
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
COL1,
COL2,
NEXT_MONDAY EXPRESSION "SELECT NEXT_DAY(SYSDATE, 'MONDAY') FROM dual",
TODAY SYSDATE
)

收到错误:

Record 16: Rejected - Error on table TABLE_NAME, column NEXT_MONDAY .
ORA-00936: missing expression

我找不到问题所在,因为当我在 SQL Developer 中 运行 表达式 SELECT NEXT_DAY(SYSDATE, 'MONDAY') FROM dual 有效时。 如果我去掉那个表达式,它就可以工作,所以其余代码就没有问题了。有人可以帮忙吗?谢谢!

最后这个方案好像解决了问题。我在双引号内添加了括号。

NEXT_MONDAY EXPRESSION "(SELECT NEXT_DAY(SYSDATE, 'MONDAY') FROM dual)"

如果这是一个表达式,则使用 表达式,而不是整个查询;不是说它不行(你发现它真的有用),只是没必要。

控制文件:

load data
infile *
replace
into table test
fields terminated by ',' optionally enclosed by '"'
trailing nullcols
(col1,
 col2,
 next_monday expression "next_day (sysdate, 'MONDAY')",
 today       sysdate
)

begindata
1,2
3,4

测试:

SQL> $sqlldr scott/tiger control=test9.ctl log=test9.log

SQL*Loader: Release 11.2.0.2.0 - Production on Pet Stu 26 21:24:37 2021

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Commit point reached - logical record count 1
Commit point reached - logical record count 2

SQL> select * from test;

      COL1       COL2 NEXT_MONDA TODAY
---------- ---------- ---------- ----------
         1          2 29.11.2021 26.11.2021
         3          4 29.11.2021 26.11.2021

SQL>