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
DB2_BIND_PARAM(3)							 1							 DB2_BIND_PARAM(3)

db2_bind_param - Binds a PHP variable to an SQL statement parameter

SYNOPSIS
bool db2_bind_param (resource $stmt, int $parameter-number, string $variable-name, [int $parameter-type], [int $data-type], [int $precision = -1], [int $scale]) DESCRIPTION
Binds a PHP variable to an SQL statement parameter in a statement resource returned by db2_prepare(3). This function gives you more con- trol over the parameter type, data type, precision, and scale for the parameter than simply passing the variable as part of the optional input array to db2_execute(3). PARAMETERS
o $stmt - A prepared statement returned from db2_prepare(3). o $parameter-number - Specifies the 1-indexed position of the parameter in the prepared statement. o $variable-name - A string specifying the name of the PHP variable to bind to the parameter specified by $parameter-number. o $parameter-type - A constant specifying whether the PHP variable should be bound to the SQL parameter as an input parameter ( DB2_PARAM_IN), an output parameter ( DB2_PARAM_OUT), or as a parameter that accepts input and returns output ( DB2_PARAM_INOUT). To avoid memory overhead, you can also specify DB2_PARAM_FILE to bind the PHP variable to the name of a file that contains large object (BLOB, CLOB, or DBCLOB) data. o $data-type - A constant specifying the SQL data type that the PHP variable should be bound as: one of DB2_BINARY, DB2_CHAR, DB2_DOUBLE, or DB2_LONG . o $precision - Specifies the precision with which the variable should be bound to the database. This parameter can also be used for retrieving XML output values from stored procedures. A non-negative value specifies the maximum size of the XML data that will be retrieved from the database. If this parameter is not used, a default of 1MB will be assumed for retrieving the XML output value from the stored procedure. o $scale - Specifies the scale with which the variable should be bound to the database. RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 Binding PHP variables to a prepared statement The SQL statement in the following example uses two input parameters in the WHERE clause. We call db2_bind_param(3) to bind two PHP variables to the corresponding SQL parameters. Notice that the PHP variables do not have to be declared or assigned before the call to db2_bind_param(3); in the example, $lower_limit is assigned a value before the call to db2_bind_param(3), but $upper_limit is assigned a value after the call to db2_bind_param(3). The variables must be bound and, for parameters that accept input, must have any value assigned, before calling db2_execute(3). <?php $sql = 'SELECT name, breed, weight FROM animals WHERE weight > ? AND weight < ?'; $conn = db2_connect($database, $user, $password); $stmt = db2_prepare($conn, $sql); // We can declare the variable before calling db2_bind_param() $lower_limit = 1; db2_bind_param($stmt, 1, "lower_limit", DB2_PARAM_IN); db2_bind_param($stmt, 2, "upper_limit", DB2_PARAM_IN); // We can also declare the variable after calling db2_bind_param() $upper_limit = 15.0; if (db2_execute($stmt)) { while ($row = db2_fetch_array($stmt)) { print "{$row[0]}, {$row[1]}, {$row[2]} "; } } ?> The above example will output: Pook, cat, 3.2 Rickety Ride, goat, 9.7 Peaches, dog, 12.3 Example #2 Calling stored procedures with IN and OUT parameters The stored procedure match_animal in the following example accepts three different parameters: o an input (IN) parameter that accepts the name of the first animal as input o an input-output (INOUT) parameter that accepts the name of the second animal as input and returns the string TRUE if an animal in the database matches that name o an output (OUT) parameter that returns the sum of the weight of the two identified animals In addition, the stored procedure returns a result set consisting of the animals listed in alphabetic order starting at the animal corresponding to the input value of the first parameter and ending at the animal corresponding to the input value of the second parameter. <?php $sql = 'CALL match_animal(?, ?, ?)'; $conn = db2_connect($database, $user, $password); $stmt = db2_prepare($conn, $sql); $name = "Peaches"; $second_name = "Rickety Ride"; $weight = 0; db2_bind_param($stmt, 1, "name", DB2_PARAM_IN); db2_bind_param($stmt, 2, "second_name", DB2_PARAM_INOUT); db2_bind_param($stmt, 3, "weight", DB2_PARAM_OUT); print "Values of bound parameters _before_ CALL: "; print " 1: {$name} 2: {$second_name} 3: {$weight} "; if (db2_execute($stmt)) { print "Values of bound parameters _after_ CALL: "; print " 1: {$name} 2: {$second_name} 3: {$weight} "; print "Results: "; while ($row = db2_fetch_array($stmt)) { print " {$row[0]}, {$row[1]}, {$row[2]} "; } } ?> The above example will output: Values of bound parameters _before_ CALL: 1: Peaches 2: Rickety Ride 3: 0 Values of bound parameters _after_ CALL: 1: Peaches 2: TRUE 3: 22 Results: Peaches, dog, 12.3 Pook, cat, 3.2 Rickety Ride, goat, 9.7 Example #3 Inserting a binary large object (BLOB) directly from a file The data for large objects are typically stored in files, such as XML documents or audio files. Rather than reading an entire file into a PHP variable, and then binding that PHP variable into an SQL statement, you can avoid some memory overhead by binding the file directly to the input parameter of your SQL statement. The following example demonstrates how to bind a file directly into a BLOB column. <?php $stmt = db2_prepare($conn, "INSERT INTO animal_pictures(picture) VALUES (?)"); $picture = "/opt/albums/spook/grooming.jpg"; $rc = db2_bind_param($stmt, 1, "picture", DB2_PARAM_FILE); $rc = db2_execute($stmt); ?> SEE ALSO
db2_execute(3), db2_prepare(3). PHP Documentation Group DB2_BIND_PARAM(3)