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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to pass a variable to an update sql statement inside a loop
# 1  
Old 04-14-2010
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.

Code:
sqlplus -s ${USERNAME}/${PASSWORD}@${SID} << END1 >> $LOGFILE
whenever sqlerror exit
set serveroutput on size 1000000
declare
  l_rc                  varchar2(1)   := null;
  cursor c1 is
    select first_name as acct_id,
      from srtable;
begin
  dbms_output.enable(1000000);
  for i in c1 loop
         update srtable
         set appt_notes = 'N'
         where first_name = i.acct_id;
         commit;
  end loop;
END1

this is the error:
-6502 ORA-06502: PL/SQL: numeric or value error: character to number conversion

does anyone know the correct syntax for my where clause? Need help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass a shellscript variable to a sql file?

Hi, i wan't to pass a shellscript variable to a sql file. a.sql select $field from dual; the way i am calling this is through sqlplus field_name="sysdate" sqlplus -s username/password@hostname:port/servicename <<EOF @a.sql $field_name EOF (4 Replies)
Discussion started by: reignangel2003
4 Replies

2. HP-UX

Unable to pass a space inside a variable shell scripting

Can anyone help me in solving this ? p=`date` e=`echo $p | awk '{print $2,$3}'` # echo $p Wed Aug 4 12:00:08 IST 2013 but when I am echoing the value of e it is giving me with one space. As shown below: # echo $e Aug 4 I need this value to be exact as found in... (6 Replies)
Discussion started by: Kits
6 Replies

3. Shell Programming and Scripting

UNIX variable to SQL statement

The following is my script : #!/bin/bash echo "please give app_instance_id" read app_instance_id echo "id is $app_instance_id" export app_id=app_instance_id sqlplus -s nnviewer/lookup@//nasolora008.enterprisenet.org:1521/LOAD3 @test.sql<<EOF SPOOL /home/tibco/MCH/Data/qa/raak/name.xls... (4 Replies)
Discussion started by: raakeshr
4 Replies

4. Shell Programming and Scripting

Update file record inside read loop

Hi, I am reading file records inside a while loop, and want to update the record when certain condition is met. How can I update a file while being read? I want to avoid using temporary files, copy, rename, ... while IFS=',' read -r f1 f2 do function(f1,f2) if then <add... (1 Reply)
Discussion started by: ysrini
1 Replies

5. Shell Programming and Scripting

issues with sql inside if statement

Hi, I have problem with the following code. My IF block is not executed. And I see "syntax error near unexpected token `)'" error for line "EOF" in the stats_function(). but when I comment the IF block I don't see this error. Kindly help me with this issue. clean_function() {... (10 Replies)
Discussion started by: babom
10 Replies

6. Shell Programming and Scripting

How to call an sql script inside a while statement in KSH

Hi all, I'm trying to run an sql inside a loop which looks like this #!bin/ksh while IFS=, read var1 var2 do sqlplus -s ${USERNAME}/${PASSWORD}@${ORACLE_SID} << EOF insert into ${TABLE} ( appt_date ) values ( '${var1 }' ); ... (6 Replies)
Discussion started by: ryukishin_17
6 Replies

7. Shell Programming and Scripting

Pass a variable to SQL script

Hi Guys, I like to pass a variable to a sql file in a unix script.. I tried a below code.. var=200903 db2 -vf test.sql 200903 test.sql is as below. select * from db2.users where quarter = $1; Please tell me where i go wrong.. Thanks in advance, Magesh (2 Replies)
Discussion started by: mac4rfree
2 Replies

8. Shell Programming and Scripting

Pass variable to sql

Please help. I got these error. I'm try to pass variable extract from data-file.txt to sql file(select.sql). cat: cannot open select cat: cannot open * cat: cannot open from cat: cannot open user cat: cannot open where cat: cannot open name=$list; #!/bin/bash list=`sed q... (3 Replies)
Discussion started by: killboy
3 Replies

9. Shell Programming and Scripting

variable inside variable inside loop headache

Hi Gurus I have a file called /tmp/CMDB which looks like this serial: 0623AN1208 hostname: server1 model: x4100 assetID: 1234 I am writing a for loop that will go through this file line by line creating a variable of itself. Using the first iteration of the loop (i.e. the first line) as... (6 Replies)
Discussion started by: hcclnoodles
6 Replies

10. Shell Programming and Scripting

ksh: A part of variable A's name is inside of variable B, how to update A?

This is what I tried: vara=${varb}_count (( vara += 1 )) Thanks for help (4 Replies)
Discussion started by: pa3be
4 Replies
Login or Register to Ask a Question
while(n)						       Tcl Built-In Commands							  while(n)

__________________________________________________________________________________________________________________________________________________

NAME
while - Execute script repeatedly as long as a condition is met SYNOPSIS
while test body _________________________________________________________________ DESCRIPTION
The while command evaluates test as an expression (in the same way that expr evaluates its argument). The value of the expression must a proper boolean value; if it is a true value then body is executed by passing it to the Tcl interpreter. Once body has been executed then test is evaluated again, and the process repeats until eventually test evaluates to a false boolean value. Continue commands may be exe- cuted inside body to terminate the current iteration of the loop, and break commands may be executed inside body to cause immediate termi- nation of the while command. The while command always returns an empty string. Note: test should almost always be enclosed in braces. If not, variable substitutions will be made before the while command starts execut- ing, which means that variable changes made by the loop body will not be considered in the expression. This is likely to result in an infinite loop. If test is enclosed in braces, variable substitutions are delayed until the expression is evaluated (before each loop iter- ation), so changes in the variables will be visible. For an example, try the following script with and without the braces around $x<10: set x 0 while {$x<10} { puts "x is $x" incr x } SEE ALSO
break(n), continue(n), for(n), foreach(n) KEYWORDS
boolean value, loop, test, while Tcl while(n)