Return code from PL/SQL Code


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Return code from PL/SQL Code
# 1  
Old 05-29-2003
Return code from PL/SQL Code

Hi Guys,
I was just wondering if anybody can help me with this problem.

OK, how we can get a value back from PL/SQL Script (not stored procedure/function)

See the below example: (for example aaa.sh)

#!/bin/ksh

VALUE=`sqlplus -s user/password@test_id <<EOF
@xxx.sq
EOF`
echo $VALUE

And xxx.sql is like below:

DECLARE
x number = 10;
y number = 0;
BEGIN
y = x /2;
END;
/
exit

OK, I'd like to get the value of "y" variable from xxx.sql back into the calling aaa.sh VALUE variable...

Mind you "exit y;" doesn't help...

Thanks in advance.


l
# 2  
Old 05-29-2003
try something like this...have to be honest I dont do much PL/SQL programming, rather I maintain some of what we have that is in our ksh scripts. here is a sample.

sqlplus -s $ORA_UID/$ORA_PWD << EOF
whenever sqlerror exit 9; --Arbitrary Return Code
variable error_cd number

BEGIN
:error_cd = 1;
pkg_do_some_stuff.call_this_function ( :error_cd ) ;

END;
/

exit :error_cd
EOF

MY_NEW_RETURN_CD=$?

if [ $MY_NEW_RETURN_CD -ne 0 ]
then
do some really cool stuff
fi
# 3  
Old 05-30-2003
Google,
Thanks for the prompt reply.
As I mentione before I'd like to get a value (like a value of a variable) from PL/SQL "SCRIPT" (not a function or procedure) back to the calling Unix script... I know how to do it when I call a stored function simply by return a value (return somevarableSmilie
Mind you I can not pass a value to a PL/SQL script (or I don't know how)

Thanks again...
# 4  
Old 05-30-2003
Not sure if this is really going to help you, but in Informix I would do something like this:

dbaccess $DBNAME - << ! 2>/dev/null | grep -v "^$" | sed -e 's/value//g' | read SOD_FILE

set isolation to dirty read;
select value from $PARAMTABLE
where parameter_key = 'SOD_FILE' and parameter_grp = 'extract_dates'
and gems_site = '$SITE'
!

dbaccess returns the result of the sql to stdout which is manipulated by sed and grep for the desired result and read into SOD_FILE.

(The dbaccess command could be back quoted and SOD_FILE set by assignment as you have done in your example).

Note here the use of environment variables (PARAMTABLE and SITE) embedded in the SQL. KSH will expand these variables and substitute their values into the sql before the dbaccess command is run.

Alternatively you could generate an sql file on the fly and clear it down afterwards. If you use the echo command, again the shell will expand environment variables.

MBB.
# 5  
Old 05-30-2003
Put set serverouput on
and add dbms_output.put_line(to_char(y)); in @xxx.sql.

Also why r u using EOF? will
VALUE=`sqlplus -s user/password@test_id < @xxx.sq`
this doesn't work?

Regards,
Yeheya
# 6  
Old 05-30-2003
Thanks Yeheya... It works....
Thanks to mbb and google for their contribution...
# 7  
Old 06-03-2003
MySQL Tip of the Day

I subscribe to a UNIX tip of the day from UGU and it just so happens that I received a tip on accessing our parameters from Oracle. Thought I would post it since it was differant from the solution provided...



OUT PARAMETER FROM ORACLE

Ever wanted to execute an
Oracle Procedure which contains
an out parameter, and use the
value returned from the out
parameter in the shell variable.

Try out this. The procedure
test1 adds two nos. and returns
output into the out parameter.

export ORACLE_HOME=< type in your Oracle Home Path >
export ORACLE_SID=< Mention the Oracle SID >
export PATH=$ORACLE_HOME:$ORACLE_HOME/bin:$PATH # This Path
is set to access the sqlplus executable
dummyvar=`sqlplus -s tcon4iqalib/tcon4iqalib <<end
set pagesize 0 feedback off ver off heading off echo off
serverout on
variable verr_mesg number
exec test1(4,5,:VERR_MESG)
print verr_mesg
exit;
end`
echo " Error is " $dummyvar
echo " Result is " $dummyvar
echo $dummyvar
#end of shell script

This tip generously supported by: (edited)

FORUM RULE: NO EMAIL ADDRESSES (ANTISPAM RULE) - Neo
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Expect return code

Hello everyone Can some help me with understand return code in expect #!/usr/bin/expect set timeout 1 set SRV set user set pw spawn ssh $user@$SRV expect { "(yes/no)? " { send "yes\r" ; exp_continue } "assword: " { send "$pw\r" ; exp_continue } eof }... (2 Replies)
Discussion started by: vikus
2 Replies

2. Shell Programming and Scripting

How could I use the value of return code

Hello, I am woring on a script where I am getting strange situation.This script actually fetch the source code and tar that code and send to NAS location.This code resides in MKS tool...and we are fetching the source code on checkpoint label basis and script is working fine.First it synch the... (0 Replies)
Discussion started by: anuragpgtgerman
0 Replies

3. UNIX for Advanced & Expert Users

Call parallel sql scripts from shell and return status when both sql are done

Hi Experts: I have a shell script that's kicked off by cron. Inside this shell script, I need to kick off two or more oracle sql scripts to process different groups of tables. And when both sql scripts are done, I will continue in the shell script to do other things like checking processing... (3 Replies)
Discussion started by: huasheng8
3 Replies

4. Shell Programming and Scripting

Need to return fail or pass from shell script on the basis of pl/sql code execution

Hi guys, I am quite new in shell scripting. I am tring to promote some oracle jobs into control-M. In control-M, I am calling a script which establishes a connection with database and execute some procedures. Now I want if that PL/sql Block got failed script should return failure to... (2 Replies)
Discussion started by: alok1301
2 Replies

5. Shell Programming and Scripting

return code help

Hello folks, I have a question that if i type ls command and type echo $? it always show "0", how i could do this change that when i type ls it will show me 1, actually i want to change the return code of commands from 0 to 1. Thanks Bash (5 Replies)
Discussion started by: learnbash
5 Replies

6. Shell Programming and Scripting

Need help with return code 1...

Hi Guys,, I am having a unix script which is running the DB2 Insert command. For the insert command, there were no records to be updated. SQL0100W No row was found for FETCH, UPDATE or DELETE; or the result of a query is an empty table. SQLSTATE=02000 + + echo 1 STAGE_RC=1 + ] ... (6 Replies)
Discussion started by: mac4rfree
6 Replies

7. UNIX for Dummies Questions & Answers

to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's

Hi All, Can anyone please let me know the syntax / how to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 'system()' function and '${?}'. I am in a process to send the mail automatically with an attachment to bulk users. I have used 'Mailx' and 'Unencode'... (0 Replies)
Discussion started by: manas6
0 Replies

8. Shell Programming and Scripting

return code from script

hey all, I have a simple script #!/bin/bash ./cron.sh test_a.txt & ./cron.sh test_b.txt & wait I want to invoke another program based on the return status of the above calls. How am I were to get that? Thanks! (2 Replies)
Discussion started by: mpang_
2 Replies

9. Shell Programming and Scripting

asking about return code

hi all my system is linux red hat i have a script that runs some object . the object return some code to the system i see the code by writing echo $? i want to ask in the script if $? equals 14 how shell is do that in the script thanks (3 Replies)
Discussion started by: naamas03
3 Replies

10. UNIX for Advanced & Expert Users

return code of a process

two programs A and B writting in c++ I am using A to B and I want to know the return code of B. in B ------------------------ int main() { return 11; } ------------------------ in A ------------------------ int main() { system(A); } ------------------------ Is it the right way... (1 Reply)
Discussion started by: filedeliver
1 Replies
Login or Register to Ask a Question