error while updating rows in sql with values in array variable

Hi,
I need to update rows in a table based on the values in an array variable.
code is :

while read line
           do
             error_msg[$index]="$(echo $line)"
             index=`expr  $index+1`
           done <"logs/$ffile"
rows_count=${#error_msg
[*]}
i=0
while [ $i -lt $rows_count ]
do
echo "error msgs is ${error_msg}"
err_msg=`echo ${error_msg}`
i=`expr $i + 1`
rec_num=`echo ${error_msg}| cut -d: -f2`
echo "record number - $rec_num"
oput=`sqlplus -s mig/mig@dev01<<END
set linesize 200
set pagesize 200
SET NEWPAGE 0
SET SPACE 0
SET ECHO OFF
SET FEEDBACK OFF
SET HEADING OFF
SET MARKUP HTML OFF SPOOL OFF
set termout off
WHENEVER SQLERROR EXIT 1;
update mass_upload set error_msg = '$err_msg' ,status_flag = 'ER' where srl_num = to_number($rec_num);
commit;
exit;
END`
i=`expr $i + 1` 
echo "${error_msg}"
i=`expr $i + 1`
done

In the above code, SQL connection is made for every update. is there any way to update all the rows in one sql connection instead of opening it multiple times?
kindly please help.

Extract the sql part alone.. try the below ..

while read line
do
error_msg[$index]="$(echo $line)"
index=`expr $index+1`
done <"logs/$ffile"
rows_count=${#error_msg
[*]}
i=0
while [ $i -lt $rows_count ]
do
echo "error msgs is ${error_msg}"
err_msg=`echo ${error_msg}`
i=`expr $i + 1`
rec_num=`echo ${error_msg}| cut -d: -f2`
echo "record number - $rec_num"
echo "update mass_upload set error_msg = '$err_msg' ,status_flag = 'ER' where srl_num = to_number($rec_num);" >> /path/to/sqlfile
i=`expr $i + 1` 
echo "${error_msg}"
i=`expr $i + 1`
done
## Invoke that sql file alone ( Please check the syntax of update command before executing the below code .. )
sqlplus -s mig/mig@dev01<<END
set linesize 200
set pagesize 200
SET NEWPAGE 0
SET SPACE 0
SET ECHO OFF
SET FEEDBACK OFF
SET HEADING OFF
SET MARKUP HTML OFF SPOOL OFF
set termout off
WHENEVER SQLERROR EXIT 1;
@/path/to/sqlfile;
commit;
exit;
END

thanks jayan! :slight_smile:
its working..