2

I am trying to insert 1 column from CSV into 2 different oracle columns. but it looks like SQL Loader looks at least n fields from CSV to load n columns in oracle and my CTL script does not work for loading n field from CSV to n+1 column in Oracle where I am trying to load one of the field into 2 different oracle columns. Plz advise

Sample data file is:

id,name,imei,flag
1,aaa,123456,Y

my oracle table has below column

create table samp (
id number,
name varchar2(10),
imei varchar2(10),
tac varchar2(3),
flag varchar2(1) )

i need to load the imei from csv onto imei in Oracle Table and substr(imei,1,3) into tac Oracle column

my Control file is:

OPTIONS (SKIP=1)
load data
 infile 'xxx.csv'
 badfile 'xxx.bad'
 into table yyyy
 fields terminated by "," 
 TRAILING NULLCOLS
 ( id,name,imei,tac "substr(:imei,1,3)", flag)

Error from the log file:

Record 1: Rejected - Error on table yyyy, column flag
Column not found before end of logical record (use TRAILING NULLCOLS)
1
  • Is flag 'aaa' or 'Y'? Perhaps check the FILLER option. Commented Sep 19, 2015 at 1:04

1 Answer 1

3

Ok, keep in mind the control file matches the input data by field in the order listed, THEN the name as defined is used to match to the table column.

The trick is to call the FIELD you need to use twice by something other than an actual column name, like imei_tmp and define it as BOUNDFILLER which means use it like a FILLER (don't load it) but remember it for future use. After the flag field, there are no more data fields so SQLLDR will try to match using the column names.

This is untested, but should get you started (the call to TRIM( ) may not be needed):

...
( id,
  name,
  imei_tmp  BOUNDFILLER,
  flag,
  imei      "trim(:imei_tmp)",
  tac       "substr(:imei_tmp,1,3)"
)
Sign up to request clarification or add additional context in comments.

3 Comments

Your proposed solution does not work for me with Oracle 12. If the csv file has only 5 columns, then SQLLdr only processes 5 field entries from the control file.
Are you using the TRAILING NULLCOLS clause? You may want to start a new question where you include your data, control and log files too.
Yes, I were using TRAINLING NULLCOLS. Problem was that I used only FILLER and BOUNDFILLER for ALL csv columns. In that case, SQLLdr does seem to stop looking at control file lines when ${numberOfCsvFields} lines have been processed. When I map to one real column somewhere, then SQLLdr carries on with the "excess" lines.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.