SQLPLUS and update statements using bind variables


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users SQLPLUS and update statements using bind variables
# 1  
Old 08-08-2007
SQLPLUS and update statements using bind variables

Hello-

The code below works fine expect that it does not update the table CTL_INTERFACE "red highlight". Any idea what I'm doing wrong here?

ThanksSmilie

# coNNECT to the database and insert a row then get the new row id
cycle_id=`sqlplus -S $XXX_USER/$XXX_PW@$XXX_CONNECT << EOF

SET ECHO OFF NEWP 0 SPA 0 PAGES 0 FEED OFF HEAD OFF TRIMS ON
VARIABLE cycle_id NUMBER;
WHENEVER SQLERROR EXIT SQL.SQLCODE ROLLBACK;

INSERT INTO ctl_cycle(cycle_id,cycle_status_desc,cycle_eff_dt,cycle_desc,interface_id) values(SEQ_CTL_CYCLE.nextval,'$CYCLE_STAT',SYSDATE,'$CYCLE_DESC','$INTR
FC_ID');
commit;

SELECT MAX(cycle_id) INTO :cycle_id
FROM ctl_cycle
WHERE interface_id='$INTRFC_ID';

UPDATE CTL_INTERFACE
set CYCLE_ID=:cycle_id
where interface_id='$INTRFC_ID';
commit;


exit;
EOF`
# 2  
Old 08-09-2007
the cycle_id may not be getting populated

The cycle_id may not be getting populated. Make this change and try,
Code:
exec SELECT MAX(cycle_id) INTO :cycle_id
FROM ctl_cycle
WHERE interface_id='$INTRFC_ID';

# 3  
Old 08-18-2007
the post of ranj@chn points in a good direction. perhaps it will be useful to look at the errormessages your fine working script produces. these are stored in the unix-variable cycle_id. you can add a
Code:
spool output.lst

at the beginning of your sqlplus-script and a
Code:
spool off

at the end. the file output.lst also contains this output
mfg guenter
# 4  
Old 08-19-2007
hey.....
you can try these follwoing 2 methods,

1.....could you please try the upate statement using another sqlplus block,as as your existing block is not returning anything......
since you have used cycle_id=`sqlplus -S $XXX_USER/$XXX_PW@$XXX_CONNECT << EOF

i think thru the max value getting out from select stmt is not populating for update one.

2.......you can combine the update with the select one as follows,
UPDATE CTL_INTERFACE
set CYCLE_ID=(SELECT MAX(cycle_id) FROM ctl_cycle
WHERE interface_id='$INTRFC_ID')
where interface_id='$INTRFC_ID';


but without any cycle_id=`sqlplus -S $XXX_USER/$XXX_PW@$XXX_CONNECT << EOF


just simple use :`sqlplus -S $XXX_USER/$XXX_PW@$XXX_CONNECT << EOF
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Programming

Using tops command to update NSLog statements in objective-c code

In my objective-c code base I have several NSLog statements. eg. NSLog(@"Here is the message without arguments"); NSLog(@"Here is the message with arguments: %s, %s","argument1","argument2"); Now I want to do two things: First to do: updating NSLog statements with... (0 Replies)
Discussion started by: Miraaj
0 Replies

2. Homework & Coursework Questions

Grep, Variables, IF statements... Fun

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: The issue I am having is part of a validation problem. My script will validate 3 or 4 parameters entered by the... (4 Replies)
Discussion started by: JonLaberge
4 Replies

3. Shell Programming and Scripting

[Help] Grep, Variables, IF statements... Fun

Hello, this will be my first post. I've been browsing around for a bit and have found a lot of useful information on here, hopefully a solution can be provided to me. Issue: Alright, I am looking to search for strings within a file using variables. I have a script that will accept 3 or 4... (2 Replies)
Discussion started by: JonLaberge
2 Replies

4. Shell Programming and Scripting

sqlplus update issue

Hi all, I'm facing a problem with a query in a shell script (AIX). sqlplus -s NAME/PASS@SCHEMA<<EOF set echo off UPDATE HISTORY SET HISTORY.ID = (SELECT OFFER.ID FROM OFFER WHERE HISTORY.ID=TO_NUMBER(OFFER.CODE)) WHERE EXISTS (SELECT OFFER.ID FROM OFFER WHERE... (5 Replies)
Discussion started by: deeper
5 Replies

5. Shell Programming and Scripting

stored procoedure bind variables in shell

Hi , I have a pl/sql procedure which takes its input from a shell script, and deletes rows from db table based on the input. I've dbms_output.put_line statments in procedure which i want to capture and display in the script for example, if no rows have been deleted, i have to stop executing... (1 Reply)
Discussion started by: justchill
1 Replies

6. Shell Programming and Scripting

put value of multiple sql statements into unix variables

i want to use multple sql count statements and store these count values in unix variable but in one connection only i.e. in only 1 time database should be hit ,which is the main requirement. (1 Reply)
Discussion started by: sw@pnil
1 Replies
Login or Register to Ask a Question