2

Hi I'm trying to execute PL SQL Procedure from my Shell Script and get the return value (out value), but it's not working. Can anyone advise what I'm doing wrong? Here's what I have:

output="$(sqlplus -S user/pw@//ip:1521/db <<ENDOFSQL
set serveroutput on;
DECLARE
    v_return PLS_INTEGER;
BEGIN
    PKG.Procedure(v_return);
    DBMS_OUTPUT.PUT_LINE(v_return);
END;
exit;
ENDOFSQL)"

echo $output 
3
  • Lets simply this by commenting out PKG.procedure(v_return) and replacing it with something static; set it it 1 or something and see if you get some output that way then we can say the issue is with the package. Commented Feb 3, 2015 at 18:32
  • 1
    Define "not working"! what is your error message? Commented Feb 3, 2015 at 22:20
  • Thanks for replies. I actually got it to work. I'll answer my own question with my solution. Commented Feb 4, 2015 at 14:43

1 Answer 1

5

After a long day of trial and error I finally got it working with the below script:

#!/bin/ksh

CODE=`sqlplus -S $SCHEMA/$PW@//$IP_PORT/$DB << EOM
Set timing on
Set serveroutput on
Whenever sqlerror exit failure;
Whenever  oserror exit failure;
declare
v_return number;
begin
PKG.Procedure(v_return);
end;
/
EOM`

if [ $? != 0 ]
then
 echo  "process failed."
 exit 1
fi

exit $?
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.