6

我正在尝试从文件加载数据,我想将 CREATED_DATE 和 UPDATED_DATE 设置为 SYSDATE 并将 CREATE_BY 和 UPDATED_BY 设置为 USER

这是我正在使用的表:

CREATE TABLE CATALOG
(CNO NUMBER,
CTITLE VARCHAR2(25),
CREATED_BY VARCHAR2(10) NOT NULL,
CREATED_DATE DATE NOT NULL,
UPDATED_BY VARCHAR2(10) NOT NULL,
UPDATED_DATE DATE NOT NULL,
CONSTRAINT CATALOG_PK Primary Key (CNO));

这是数据文件:

1,"Title 1"
2,"Title 2"
3,"Title 3"
4,"Title 4"
5,"Title 5"
6,"Title 6"

和我的控制文件:

LOAD DATA
 INFILE "mydata.csv"
 INTO TABLE CATALOG
 FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"'    
 (CNO,CTITLE,CREATED_BY "USER", CREATED_DATE "SYSDATE", UPDATED_BY "USER", UPDATED_DATE "SYSDATE")

当我尝试使用 SQL Loader 加载它时...所有记录都被拒绝:

Record 1: Rejected - Error on table CATALOG, column CREATED_BY.
Column not found before end of logical record (use TRAILING NULLCOLS)
Record 2: Rejected - Error on table CATALOG, column CREATED_BY.
Column not found before end of logical record (use TRAILING NULLCOLS)
.......

任何想法我做错了什么?提前致谢。

4

2 回答 2

8

只需按照 Oracle 所说的去做:添加TRAILING NULLCOLS到您的控制文件中:

LOAD DATA
 INFILE "mydata.csv"
 INTO TABLE CATALOG
 FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS  
 (CNO,CTITLE,CREATED_BY "USER", CREATED_DATE "SYSDATE", UPDATED_BY "USER", UPDATED_DATE "SYSDATE")

这是必需的,因为只有前两列在输入文件中。剩下的纯粹是计算的。

如果您不指定它,Oracle 会尝试读取第三、第四等列,但找不到。

于 2010-08-15T18:16:26.327 回答
-1

在控制文件中试试这个

(CNO,CTITLE,CREATED_BY "USER", CREATED_DATE SYSDATE, UPDATED_BY "USER", UPDATED_DATE SYSDATE)
于 2015-02-14T21:21:39.363 回答