Update a column in table using SQL*Loader
Asked Answered
M

1

6

I have written an SQL script having the below query. The query works fine.

update partner set is_seller_buyer=1 where id in (select id from partner
where names in
(
  'A','B','C','D','E',... -- Around 100 names.
));

But now instead of writing around 100 names in a query itself, I want to fetch all the names from the CSV file. I read about SQL*Loader on the Internet, but I did not get much on an update query.

My CSV file only contain names.

Enter image description here

I have tried

  load data
  infile 'c:\data\mydata.csv'
  into table partner set is_wholesaler_reseller=1
  where id in (select id from partner
  where names in
  (
    'A','B','C','D','E',... -- Around 100 names.
  ));
  fields terminated by "," optionally enclosed by '"'
  ( names, sal, deptno )

How can I achieve this?

Madeleinemadelena answered 1/2, 2012 at 5:18 Comment(3)
Reproduced without attribution (license violation) at YouTube.Faircloth
Or rather, proper attribution (it is insufficient).Faircloth
(Some valid comment characters in SQL.)Faircloth
P
9

SQL*Loader does not perform updates, only inserts. So, you should insert your names into a separate table, say names, and run your update from that:

update partner set is_seller_buyer=1 where id in (select id from partner 
where names in 
(
select names from names
));

Your loader script can be changed to:

load data
  infile 'c:\data\mydata.csv'
  into table names
  fields terminated by "," optionally enclosed by '"'         
  ( names, sal, deptno )

An alternate to this is to use External Tables which allows Oracle to treat a flat file like it is a table. An example to get you started can be found here.

Perfectionism answered 1/2, 2012 at 6:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.