views:

27

answers:

1

I'm trying to load data from a file and I want to set CREATED_DATE and UPDATED_DATE to SYSDATE and CREATE_BY and UPDATED_BY to USER

Here the table that I'm working with:

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));

and here is the data file:

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

and my control file:

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")

When I try to load it with SQL Loader...all records are rejected:

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)
.......

Any ideas what I'm doing wrong? Thanks in advance.

+2  A: 

Just do what Oracle says: add TRAILING NULLCOLS to your control file:

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")

This is required because only the first two columns are in the input file. The remaing ones are purely computed.

If you don't specify it, Oracle tries to read a third, fourth etc. column, but can't find one.

Codo
Thanks very much!
relyt