Insert one table and update another with shellscript


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Insert one table and update another with shellscript
# 1  
Old 05-21-2016
Wrench Insert one table and update another with shellscript

I have a problem with my shell script. I want to insert data from file to table1(empty) and then, compare table1 with table2 and update some fields.

The first part is correct, but the second part does not work. The only way it works is if after the first part I truncate table1 and run the script again.

I want to make everything in one time(insert data and update)

My shellscript:

Code:
    #!/bin/ksh    
DATE=`date +"%Y%m%d"`
PATH_LD=$HOME/myscripts/script_anuk
    PATH_BIN=$HOME/bin/myscripts/script_anuk
    PATH_LOG=$HOME/log/myscripts/script_anuk


    logfile=$PATH_LOG/script_anuk$FECHA.log
    logfileMod=$PATH_LOG/script_anuk_mod$FECHA.log

    # Insert 

    sqlldr parfile=$PATH_LD/script_anuk_param.par USERID=$CONSQLPLUS

    # Update
      sqlplus -s $CONSQLPLUS << EOF!

     SET SERVEROUTPUT ON

     SET FEEDBACK OFF
    exec declare cursor d1 is select d.book, d.phone,d.pencil from table1 d,table2 n where d.book = n.book; whow number:=0;begin for r1 in d1 loop update table2 set phone=r1.phone,pencil=r1.pencil where book = r1.book; whow := whow + 1;if mod(whow,10000) = 0 then commit; end if;end loop;end;
    exit
    EOF!

My .par

Par
Code:
USERID=/
CONTROL=$HOME/myscripts/script_anuk/script_anuk_param.ctl
DATA=$HOME/myscripts/script_anuk/data1.dat
LOG=$HOME/log/myscripts/script_anuk/script_anuk_param.log
BAD=$HOME/myscripts/script_anuk/error/script_anuk_param.bad
DISCARD=$HOME/myscripts/script_anuk/error/script_anuk_param.dsc
ERRORS=1000000
ROWS=500
DIRECT=FALSE

My .ctl
Code:
Ctl
LOAD DATA
INFILE *
INTO TABLE table1
APPEND
FIELDS TERMINATED BY ';'
(book  , 
phone         ,
pencil)
)


Can you help me please? Thank you! Smilie
# 2  
Old 05-26-2016
What errors are you getting? I don't see what's going wrong so it's difficult to help.

Can you paste in the output/errors you get?



Thanks,
Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

How to track table status delete/update/insert status in DB2 V10 z/os?

Dear Team I am using DB2 v10 z/os database . Need expert guidance to figure out best way to track table activities ( Ex Delete, Insert,Update ) Scenario We have a table which is critical and many developer/testing team access on daily basis . We had instance where some deleted... (1 Reply)
Discussion started by: Perlbaby
1 Replies

2. Programming

MYSQL - trigger update on record insert or update

Right I have a MYSQL database with table1 with 3 columns, colA, colB and colC. I want to combine the data in the 3 columns into a 4th column names col_comb. Here's the SQL command that works: UPDATE table1 SET `col_comb` = CONCAT( `colA` , ' - ', `colB` , ', ', `colC` ); So now I want this... (5 Replies)
Discussion started by: barrydocks
5 Replies

3. Shell Programming and Scripting

Insert bulk values in DB table using isql

Hello, Objective is to insert bulk values in DB table using isql. Following code tried: isql -SServer_name -Ddb_name -Uuser_name -Ppassword < file.txt cat file.txt for i in `cat data_value_file.txt` do insert into tempdb..temp_table11 values ('$i') go done cat... (3 Replies)
Discussion started by: manishdivs
3 Replies

4. Programming

Table Locking in Insert Command.

Hi, i have a java based tool which does insert operation in a TABLE, and in parallel the same table is used by my C++ code which does select Query. the Table will be always busy, but sometimes the table is getting locked when i try to make an insert, am bit confused whether the lock is... (0 Replies)
Discussion started by: senkerth
0 Replies

5. Shell Programming and Scripting

Insert script result into Oracle Table

Hi All, I want to insert STAT and ENDTIME values for each job in joblist into TBL_DAILY_STATUS table. Eg: insert into tbl_daily_status values(STAT,ENDTIME); Please help me on this. #!/bin/ksh joblist="com_abc_job com_abc_dot_job com_abc_seq com_abc_det" for i in $joblist do... (8 Replies)
Discussion started by: vichuelaa
8 Replies

6. Shell Programming and Scripting

select values from db1 table and insert into table of DB2

Hi I am having three oracle databases running in three different machine. their ip address is different. from one of the DB am able to access both the databases.(means am able to select values and insert values in to tables individually.) I need to fetch some data from DB1 table(say DB1 ip is... (2 Replies)
Discussion started by: aemunathan
2 Replies

7. Shell Programming and Scripting

Insert value to ORACLE table from sqlldr log

This is the sample sqlldr log: ------------------------------------------------------------------------------------------------------------ SQL*Loader: Release 9.2.0.7.0 - Production on Sun Feb 8 23:37:02 2009 Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved. Control... (13 Replies)
Discussion started by: aimy
13 Replies

8. Shell Programming and Scripting

shellscript.query Oracle table..populate in a text file

Hi Guys, I'm new to this forum as well as to UNIX shell scripting. I'm looking for a shellscript to query an Oracle database table and populate the result set of the query in a text file. Could you someone help me out with a sample code? Thanks, Bhagat (7 Replies)
Discussion started by: bhagat.singh-j
7 Replies

9. Shell Programming and Scripting

need to insert two columns (or two feilds) at the begining of the table

Hey guys/gals, So here is what i'm starting with...its a Solaris patch diag output. bash-3.0# pca -l Using /var/tmp/patchdiag.xref from Oct/20/08 Host: seiftsx4140 (SunOS 5.10/Generic_127128-11/i386/i86pc) List: missing Patch IR CR RSB Age Synopsis ------ -- - -- --- ---... (3 Replies)
Discussion started by: zeekblack
3 Replies

10. UNIX for Advanced & Expert Users

unix script for update or insert records from a file to a oracle table

Hi, I have delimited file(|). Sample data: 1|name|50009|DS24|0|12 2|name|30009|DS24|0|13 3|name|20409|DS24|0|14 4|name|20009|DS24|0|15 5|name|10009|DS24|0|16 I want to load this data into a oracle table (update and insert) Please help me the commands and also... (1 Reply)
Discussion started by: unihp1
1 Replies
Login or Register to Ask a Question