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
PDO.PREPARE(3)								 1							    PDO.PREPARE(3)

PDO
::prepare - Prepares a statement for execution and returns a statement object SYNOPSIS
public PDOStatement PDO::prepare (string $statement, [array $driver_options = array()]) DESCRIPTION
Prepares an SQL statement to be executed by the PDOStatement.execute(3) method. The SQL statement can contain zero or more named (:name) or question mark (?) parameter markers for which real values will be substituted when the statement is executed. You cannot use both named and question mark parameter markers within the same SQL statement; pick one or the other parameter style. Use these parameters to bind any user-input, do not include the user-input directly in the query. You must include a unique parameter marker for each value you wish to pass in to the statement when you call PDOStatement.execute(3). You cannot use a named parameter marker of the same name more than once in a prepared statement, unless emulation mode is on. Note Parameter markers can represent a complete data literal only. Neither part of literal, nor keyword, nor identifier, nor whatever arbitrary query part can be bound using parameters. For example, you cannot bind multiple values to a single parameter in the IN() clause of an SQL statement. Calling PDO.prepare(3) and PDOStatement.execute(3) for statements that will be issued multiple times with different parameter values opti- mizes the performance of your application by allowing the driver to negotiate client and/or server side caching of the query plan and meta information, and helps to prevent SQL injection attacks by eliminating the need to manually quote the parameters. PDO will emulate prepared statements/bound parameters for drivers that do not natively support them, and can also rewrite named or ques- tion mark style parameter markers to something more appropriate, if the driver supports one style but not the other. PARAMETERS
o $statement - This must be a valid SQL statement for the target database server. o $driver_options - This array holds one or more key=>value pairs to set attribute values for the PDOStatement object that this method returns. You would most commonly use this to set the PDO::ATTR_CURSOR value to PDO::CURSOR_SCROLL to request a scrollable cursor. Some drivers have driver specific options that may be set at prepare-time. RETURN VALUES
If the database server successfully prepares the statement, PDO.prepare(3) returns a PDOStatement object. If the database server cannot successfully prepare the statement, PDO.prepare(3) returns FALSE or emits PDOException (depending on error handling). Note Emulated prepared statements does not communicate with the database server so PDO.prepare(3) does not check the statement. EXAMPLES
Example #1 Prepare an SQL statement with named parameters <?php /* Execute a prepared statement by passing an array of values */ $sql = 'SELECT name, colour, calories FROM fruit WHERE calories < :calories AND colour = :colour'; $sth = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY)); $sth->execute(array(':calories' => 150, ':colour' => 'red')); $red = $sth->fetchAll(); $sth->execute(array(':calories' => 175, ':colour' => 'yellow')); $yellow = $sth->fetchAll(); ?> Example #2 Prepare an SQL statement with question mark parameters <?php /* Execute a prepared statement by passing an array of values */ $sth = $dbh->prepare('SELECT name, colour, calories FROM fruit WHERE calories < ? AND colour = ?'); $sth->execute(array(150, 'red')); $red = $sth->fetchAll(); $sth->execute(array(175, 'yellow')); $yellow = $sth->fetchAll(); ?> SEE ALSO
PDO.exec(3), PDO.query(3), PDOStatement.execute(3). PHP Documentation Group PDO.PREPARE(3)