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:

    #!/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

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

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

Can you help me please? Thank you! :slight_smile:

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