[SQL] Why Update is happening twice?


 
Thread Tools Search this Thread
Top Forums Programming [SQL] Why Update is happening twice?
# 1  
Old 07-10-2011
Question [SQL] Why Update is happening twice?

Example 1=>
I have unix ksh file and I am calling sql file from it.



(table 1 contains 2 rows -
ID Name
1 test't
2 Pet's
)

below sql statement is part of sql file:

update table1 set name = replace(name,'''','''''') where instr(name,'''') > 0 ;

--I see below statement in my log file
2 rows updated.


2 rows updated.

--after this update I see name is updated to test''''t and pet''''s

(Problem here is I see 2 rows updated two times.even if there is one row its getting updated two times)

--------------
Example 2)
SO I have created other ksh and sql and in that sql I have written same update and its working fine.


update table1 set name = replace(name,'''','''''') where instr(name,'''') > 0 ;

--I see below statement in my log file

2 rows updated.

--after this update I see name is updated to test''t and pet''s

--
Why there are 2 updates in first example?
# 2  
Old 07-10-2011
A possible reason is that you have a slash / at the end of your SQL, which would cause the previous SQL to be re-executed.

Code:
$ cat sql1
sqlplus -s scott/tiger << !
  update table1 set name = replace(name,'''','''''') where instr(name,'''') > 0 ;
/
!

echo Returned $?

Code:
2 rows updated.


2 rows updated.


Returned 0

If it's not that, please post the script and the SQL (using code tags).
# 3  
Old 07-10-2011
reply [SQL] Why Update is happening twice?

Hi scottn,

Thanks...

That is correct reason that \ is causing update twice. But why \ is causing twice update?

-thanks
# 4  
Old 07-10-2011
A slash (/ (not a backslash (\) as you wrote)) will cause SQL*Plus to run whatever SQL is in the SQL buffer. Since you already ran that command (update .... ;), using / will cause it to be re-executed.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Function call is not happening

set -x QM=$1 port=$2 KILLQ () { ps -efww | grep $QM | grep -v grep | tr -s " " " " | cut -d" " -f2 |xargs kill -9 sleep 3 echo "Checking the Queue" CHKQ } CRTQ () { strmqm $QM runmqlsr -m $QM -t TCP -p $port & } CHKQ () (6 Replies)
Discussion started by: nikhil jain
6 Replies

2. Fedora

Leap second happening

Have anybody heard about the Leap second problem Leap second :A leap second is a one-second adjustment that is occasionally applied to Coordinated Universal Time (UTC) in order to keep its time of day close to the mean solar time. How could i avoid such thing in my script which i deal with... (6 Replies)
Discussion started by: wnaguib
6 Replies

3. Shell Programming and Scripting

how to pass a variable to an update sql statement inside a loop

hi all, i am experiencing an error which i think an incorrect syntax for the where clause passing a variable was given. under is my code. sqlplus -s ${USERNAME}/${PASSWORD}@${SID} << END1 >> $LOGFILE whenever sqlerror exit set serveroutput on size 1000000 declare l_rc ... (0 Replies)
Discussion started by: ryukishin_17
0 Replies

4. UNIX for Dummies Questions & Answers

how to capture no. of rows updated in update sql in unix db2

hi, i am a new user in unix..and we have unix db2. i want to capture the no. of rows updated by a update db2 sql statement and redirect into a log file. I've seen db2 -m...but not sure how the syntax should be. The update sql that I'm going to run is from a file... Can you please share... (1 Reply)
Discussion started by: j_rymbei
1 Replies

5. Shell Programming and Scripting

Incrementing a variable is not happening

Hi All, Iam trying to increment a variable Following is the code #!/usr/bin/ksh i=1; i='expr $i+1'; echo $i; Output: expr $i+1 not able to understand why its happening in that way i was expecting result as 2... if the above method is worng .. can you help how i can get... (3 Replies)
Discussion started by: kiranlalka
3 Replies

6. UNIX for Dummies Questions & Answers

what's happening with my keyboard

hi everybody. i ussually use unix and windows, but mainly unix-mandriva distribution, and i have a problem. i have like main os unix, and windows as secondary, and this one is loaded by vmware application. well, when a i load vmware to execute windows afterwards when i return to unix, in this... (1 Reply)
Discussion started by: tonet
1 Replies

7. Shell Programming and Scripting

Help shell script to loop through files update ctl file to be sql loaded

I am currently trying to find a way to loop through files in a given directory and for each file modify a ctl file and sql load it. I have been using the sed command to change the infile, badfile parameters of the control file. I have not yet tried to sql load it. Requirement: files are ftp to... (1 Reply)
Discussion started by: dba_nh
1 Replies

8. AIX

Ping is happening, telnet is not happening

HI all, Ping is happening to a AIX box...but telnet is not happening... AIX box doesn't have any conslole... Please help how to resolve it. Thanks in advance .. Manu (2 Replies)
Discussion started by: b_manu78
2 Replies
Login or Register to Ask a Question