If I run the below script, I am getting the error SP2-0552: Bind variable "OUTRES" not declared. So, how to define the bind variable OUTRES and where to define?
#!/usr/bin/bash
sqlplus -s scott/tiger << EOF
declare ret varchar2(10):= '0';
begin
begin
insert into mytab(col1) values(1);
exception
when others then
ret:=ret||'1';
end;
select ret into :OUTRES from dual;
end;
/
quit
EOF
Use a bind variable in PL/SQL to access the variable from SQL*Plus. Bind variables are variables you create in SQL*Plus and then reference in PL/SQL. If you create a bind variable in SQL*Plus, you can use the variable as you would a declared variable in your PL/SQL subprogram and then access the variable from SQL*Plus.
You simply have to write a command which starts with keyword VARIABLE followed by the name of your bind variable which is completely user defined along with the data type and data width. That's how we declare a bind variable in Oracle database.
REFCURSOR bind variables can also be used to reference PL/SQL cursor variables in stored procedures. This allows you to store SELECT statements in the database and reference them from SQL*Plus. A REFCURSOR bind variable can also be returned from a stored function.
Show activity on this post. #!/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 $?
If you want to declare the bind variable in sqlplus
. use the VAR
keyword.
sqlplus -s scott/tiger << EOF
VAR OUTRES NUMBER;
BEGIN
NULL; /* Your Statements */
END;
/
EOF
You can also try quit :OUTRES
and
quit :OUTRES
EOF
MYRESULT=$?
echo $MYRESULT
It output the return status in UNIX
.
#!/usr/bin/bash
sqlplus -s scott/tiger << EOF
VAR OUTRES NUMBER;
declare ret varchar2(10):= '0';
begin
begin
EXECUTE IMMEDIATE 'insert into mytab(col1) values(1)';
exception
when others then
dbms_output.put_line(SQLERRM);
ret:=ret||'1';
end;
:OUTRES := ret;
end;
/
quit :OUTRES
EOF
MYRESULT=$?
echo $MYRESULT
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With