zetordie zetordie - 1 month ago 12
SQL Question

How to load CSV data into Oracle table that has more columns than the csv file?

I have a .csv file that contains data for only certain columns in a table. How do I import that .csv into the table leaving the other columns intact (or setting the NULL value)?

Initially the table had the same columns as the .csv file and I was using this SQL loader:

LOAD DATA
INFILE '"Path"/file.csv'
APPEND
INTO TABLE MY_TABLE
FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '"'
(
COLUMN1,
COLUMN2,
COLUMN3,
COLUMN4,
COLUMN5
)


but then I had to add some other columns in table that need to be updated with data from other tables, and I want to update them (using a trigger) when inserting the data from the .csv for the initial columns. So how do I import in table only the columns in .csv?

Answer

There is nothing you need to do.

Only the column values from the file will be sent.

The other columns will get their default value (typically NULL, but that depends on the column definition) when the rows are inserted.

Not sure what you mean with leaving the other columns intact, as SQL*Loader will only insert new rows, there is nothing to be "left intact".