SQL Loader script help with adding SYSDATE, USER
Asked Answered
S

2

6

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.

Sorel answered 14/8, 2010 at 20:21 Comment(0)
O
9

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.

Overweary answered 15/8, 2010 at 18:16 Comment(0)
H
-1

In control file try this

(CNO,CTITLE,CREATED_BY "USER", CREATED_DATE SYSDATE, UPDATED_BY "USER", UPDATED_DATE SYSDATE)
Headway answered 14/2, 2015 at 21:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.