Skip to content
Advertisement

How to read column from csv and run a update query?

I have a csv file that has 6000 rows of dates and ID numbers. I’m using SQL Oracle Developer. I’ve uploaded my CSV file into Oracle.

The CSV file table is table3. I want to update table1 with the following query. As mentioned in table3 (CSV file) has 6000 T1_ID. I want it to go through the csv file and get the T1_ID and update table1.

Since there are bunch of dates in my CSV file, I’m thinking maybe using dates would be an better option to get the T1_IDs.

update table1
set RESULT_CODE = 62
where T1_ID = ? 
CREATED_time >= ?
and CREATED_time <= ?

This is an example of what the table 3 looks like:

Advertisement

Answer

You could use a MERGE statement:

MERGE INTO TABLE1 t1
  USING (SELECT *
           FROM TABLE3) t3
    ON (t1.ID = t3.ID AND
        t3.CREATED_TIME BETWEEN TO_TIMESTAMP('01-APR-2020', 'DD-MON-YYYY')
                            AND TO_TIMESTAMP('02-MAY-2020', 'DD-MON-YYYY') - INTERVAL '0.000000001' SECOND)
  WHEN MATCHED THEN
    UPDATE SET t1.RESULT_CODE = 62;
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement