error while updating rows in sql with values in array variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting error while updating rows in sql with values in array variable
# 1  
Old 07-23-2012
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 :
Code:
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[i]}"
err_msg=`echo ${error_msg[i]}`
i=`expr $i + 1`
rec_num=`echo ${error_msg[i]}| 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]}"
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.

Last edited by Franklin52; 07-24-2012 at 08:32 AM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 07-23-2012
Extract the sql part alone.. try the below ..
Code:
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[i]}"
err_msg=`echo ${error_msg[i]}`
i=`expr $i + 1`
rec_num=`echo ${error_msg[i]}| 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]}"
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

# 3  
Old 07-23-2012
thanks jayan! Smilie
its working..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Asign to variable ksh some values of sql query

Hi, I'm trying to asign to ksh varible some values of a sql query. The output query would be: xxxx 1 yyyy 2 I do: values=`$PATH_UTI/query_sh " select think1||'------'||think2 from some_table where think3 = '$1'; ... (2 Replies)
Discussion started by: mierdatuti
2 Replies

2. Shell Programming and Scripting

Attach variable to array values

Hi All, Need a help. I am just learning Shell scripting. Need a requirement like to attach variable to array values. Value of from is AF and to is AD. froml=$(echo $from | tr '' '') tol=$(echo $to | tr '' '') Schemas=(AWQM WFCONTROLLER PROVCO PRISM) for s in "${Schemas}" do ... (3 Replies)
Discussion started by: pvmanikandan
3 Replies

3. Shell Programming and Scripting

Array Variable being Assigned Values in Loop, But Gone when Loop Completes???

Hello All, Maybe I'm Missing something here but I have NOOO idea what the heck is going on with this....? I have a Variable that contains a PATTERN of what I'm considering "Illegal Characters". So what I'm doing is looping through a string containing some of these "Illegal Characters". Now... (5 Replies)
Discussion started by: mrm5102
5 Replies

4. Shell Programming and Scripting

How to get value from array and set those values as a variable

I am new to ksh scripting, specially array. How do i get values from an array and set the value as variable and pass those variables to the different functions?? someone taught me how to get input from a file with have columns i need to read, but now i doesnt know how to set those value to be a... (7 Replies)
Discussion started by: gavin_L
7 Replies

5. Shell Programming and Scripting

storing multiple values in a array variable

Am using a find command in my script .The output may be one or more. I need to store those values in a array and need to access those. Am unable to find the solution . Any help on this will be helpful. if < code> else a=<find command output which gives the file name either 1 or more> if 1... (1 Reply)
Discussion started by: rogerben
1 Replies

6. Shell Programming and Scripting

Store values from a file into an array variable in Shell

Dear All, I have been trying to do a simple task of extracting 2 fields from the file (3 rows) and store it in an array variable. I tried with: #! /bin/bash ch=`cut -f10 tmp.txt` counter=0 for p in $pid do c=${ch} echo "$c ..$counter" counter=$((counter+1))... (2 Replies)
Discussion started by: ezhil01
2 Replies

7. Shell Programming and Scripting

Piping Unix Variable Array values into AWK

#ksh Here is my code: ERRORLIST="43032 12001 12002 12003 12004 34019 49015 49016 49017 49018 49024 49025 49026 58004 72003 12005 12006 12007 12008 12011 12012 16024 16023" for ERROR in ${ERRORLIST} do awk -v l="$lastdate" '/^....-..-../&&$0>l{d=$0}d&&/Error: '"${ERROR}"'/{print... (3 Replies)
Discussion started by: k1ko
3 Replies

8. Shell Programming and Scripting

How to print array values whose name is inside a variable

I have a array as CArray=( a1 a2 ) and a1,a2,a3 are also array as: a1=(1 2 3) a2=(3 4 5) now I have this in my code: for i in `echo "${CArray}"` do echo ${$i} done It is giving error as :"bad substitution" It should give me value as 1 2 3 3 4 5 how can I get this...Can u please... (2 Replies)
Discussion started by: joshilalit2004
2 Replies

9. UNIX for Advanced & Expert Users

sql variable as array index

hi folks i am facing problom while trying to access sql variable as array index ina unix shell script....script goes as below.. #!/bin/ksh MAX=3 for elem in alpha beeta gaama do arr=$elem ((x=x+1)) Done SQL_SERVER='servername' /apps/sun5/utils/sqsh -S $SQL_SERVER -U user -P pwd -b -h... (1 Reply)
Discussion started by: sudheer157
1 Replies

10. Shell Programming and Scripting

split variable values into array

i have these values inside variable $blah BUNGA TERATAI 3 5055 ITH 1 0 0 0 1 1 JADE TRADER 143W ITH 4 0 0 0 4 4 MOL SPLENDOR 0307A ITH 3 0 0 0 3 3 so how do I split them into array with the... (4 Replies)
Discussion started by: finalight
4 Replies
Login or Register to Ask a Question