Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update a column in table using SQL*Loader?

I have written a SQL Script having below query. 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 internet but i did not get much on update query. My csv file contain only 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 i can achieve this? Thanks in advance.

like image 723
vikiiii Avatar asked Feb 01 '12 05:02

vikiiii


People also ask

Can SQL Loader update existing rows?

you cannot update with sqlldr. And an update will update the same set of columns every time (it would be not efficient to go slow by slow and read out a row, determine what columns changed, generate an update just for them, bind to it and execute it).

What is SQL Loader with example?

SQL Loader. SQL LOADER utility is used to load data from other data source into Oracle. For example, if you have a table in FOXPRO, ACCESS or SYBASE or any other third party database, you can use SQL Loader to load the data into Oracle Tables. SQL Loader will only read the data from Flat files.

What is trailing Nullcols in SQL * Loader?

The TRAILING NULLCOLS clause tells SQL*Loader to treat any relatively positioned columns that are not present in the record as null columns. See Handling Short Records with Missing Data. The remainder of the control file contains the field list, which provides information about column formats in the table being loaded.

What are loaders in SQL?

SQL*Loader loads data from external files into tables of an Oracle database. It has a powerful data parsing engine that puts little limitation on the format of the data in the datafile. You can use SQL*Loader to do the following: Load data across a network.


1 Answers

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.

like image 126
John Doyle Avatar answered Oct 11 '22 05:10

John Doyle