Question

I am using SEQUENCE keyword in SQL Loader control file to generate primary keys. But for a special scenario I would like to use Oracle sequence in the control file. The Oracle documentation for SQL Loader doesn't mentioned anything about it. does SQL Loader support it?

Was it helpful?

Solution

I don't think so, but you can assign the sequence via the on insert trigger unless this is a direct path load.

OTHER TIPS

I have successfully used a sequence from my Oracle 10g database to populate a primary key field during an sqlldr run:

Here is my data.ctl:

LOAD DATA
INFILE 'data.csv'
APPEND INTO TABLE my_data
FIELDS TERMINATED BY ','
(
  ID "MY_SEQUENCE.NEXTVAL",
  name char
)

and my data.csv:

-1, "dave"
-1, "carol"
-1, "tim"
-1, "sue"

For some reason you have to put a dummy value in the CSV file even though you'd figure that sqlldr would just figure out that you wanted to use a sequence.

I have managed to load without using the dummy by the switching the sequence to be the last column as in :

LOAD DATA
INFILE 'data.csv'
APPEND INTO TABLE my_data
FIELDS TERMINATED BY ','
(
    name char,
    ID "MY_SEQUENCE.NEXTVAL"
)

and data.csv would be like:

"dave"
"carol"
"tim"
"sue"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top