Update the table using values from a csv file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Update the table using values from a csv file
# 1  
Old 05-29-2013
Update the table using values from a csv file

i want to run update query for oracle which is in up.sql taking values from a.csv.
I have implemented shell script to do it.
Code:
 
extn="perl"
ls -1 | while read file
do
echo "$file,$extn" > a.csv
done

up.sql contains
Code:
update file_list set filename=$1 where extn=$2;

The code to update is as below
Code:
 
while read line
file=`cut -d "," -f 1`
extn=`cut -d "," -f 2`
do
sqlplus <<END
username/password@connectstring
@update.sql $file $extn
commit;
END
done< a.csv

Since there are a large no files..i dont want to run the sqlplus command that much of time...
Is there any way to use a.csv to update the table...I tried sqlldr but it is working only for inser not for update.
# 2  
Old 05-30-2013
You could create a Oracle 'external table' linked to your file(a.csv) that contains the data to update with and perform all the updates in one update script or statement, example of external table:

Code:
-- Create oracle external table linked to a flat file(i.e. a.csv)
create table schema.table ( 
  account_num                 varchar2( 16 ),
  account_id                  varchar2( 10 ),
  rpt_num                     varchar2(  6 ),
  report_file_name            varchar2( 64 ) )
organization external (
  type              oracle_loader
  default directory TMP
  access parameters (
    records delimited by newline
    badfile      'accounts.bad'
    discardfile  'accounts.dis'
    logfile      'accounts.log'
    fields  terminated  by '-'
    missing field values are null
    ( account_num,
      account_id,
      rpt_num,
      report_file_name ) )
    location ( 'a.csv' ) )

You can then use a 'update' sql statement or a cursor in a sql script to perform your updates.
# 3  
Old 05-30-2013
Or use sqlldr to load a temporary table, and perform updates from there.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Create a pivot table from CSV file

Gents, Can you please help me to create a pivot table from a csv file. ( I have zip the csv file) Using the file attached, columns 1,28 and 21 i would like to get something like this output JD Val 1 2 3 4 5 6 7 8 9 10 11 12 Total... (4 Replies)
Discussion started by: jiam912
4 Replies

2. Shell Programming and Scripting

Match columns from two csv files and update field in one of the csv file

Hi, I have a file of csv data, which looks like this: file1: 1AA,LGV_PONCEY_LES_ATHEE,1,\N,1,00020460E1,0,\N,\N,\N,\N,2,00.22335321,0.00466628 2BB,LES_POUGES_ASF,\N,200,200,00006298G1,0,\N,\N,\N,\N,1,00.30887539,0.00050312... (10 Replies)
Discussion started by: djoseph
10 Replies

3. Shell Programming and Scripting

awk file to read values from Db2 table replacing hard coded values

Hi, I want to replace a chain of if-else statement in an old AWK file with values from Db2 table or CSV file. The part of code is below... if (start_new_rec=="true"){ exclude_user="false"; user=toupper($6); match(user, "XXXXX."); if (RSTART ==2 ) { ... (9 Replies)
Discussion started by: asandy1234
9 Replies

4. Shell Programming and Scripting

Convert file in csv or table

Hi there, i have a file like that in attachment (PLEVA3_280711_SAP.txt), i would extract some basic information from it and report in a new file or table like this: i try to use bash and i extract the single object in this way (see attach scriptino.sh), but i receive a strange... (5 Replies)
Discussion started by: alen192
5 Replies

5. UNIX for Dummies Questions & Answers

Storing data from a table into a csv file

Hi I need to write a bash script to take the data stored in 3 oracle tables .. and filter them and store the results in a csv file. It is an Oracle database Thank you (1 Reply)
Discussion started by: ladyAnne
1 Replies

6. Shell Programming and Scripting

Store table contents in csv file

I need to write a script to store the contents of a table in a csv file I'm using Toad, it's a Oracle database. (5 Replies)
Discussion started by: ladyAnne
5 Replies

7. Emergency UNIX and Linux Support

Global update on a file based on a table

Hi, I 'd like to update the below highlighted values in a sample file based on the following table: 8283879A25918000000000005400000000000065629TTF3 8683884F40273000000000003900000000000047399TTF3 8883884FG0063000000000002600000000000031599TTF3... (7 Replies)
Discussion started by: er_ashu
7 Replies

8. Shell Programming and Scripting

Need to compare two csv files values and write into another csv file

Hi all, Am new to scripting. So i just need your ideas to help me out. Here goes my requirement. I have two csv files 1.csv 2.csv abc,1.24 abc,1 def,2.13 def,1 I need to compare the first column of 1.csv with 2.csv and if matches then need to compare... (2 Replies)
Discussion started by: chinnahyd
2 Replies

9. UNIX for Advanced & Expert Users

How to load comma seperated values file (*.csv) into Oracle table

Hi all I need to input values in a .csv file into my Oracle table running in Unix, I wonder what would be the command to do so... The values are recorded in an excel file and I tried using a formatted text file to do so but failed because one of the field is simply too large to fit in the... (4 Replies)
Discussion started by: handynas
4 Replies

10. UNIX for Dummies Questions & Answers

How to load comma seperated values file (*.csv) into Oracle table

Hi all I need to input values in a .csv file into my Oracle table running in Unix, I wonder what would be the command to do so... The values are recorded in an excel file and I tried using a formatted text file to do so but failed because one of the field is simply too large to fit in the... (5 Replies)
Discussion started by: handynas
5 Replies
Login or Register to Ask a Question