Pages

Thursday, October 17, 2013

Return status from PL/SQL


#!/bin/ksh93

sqlplus  -s xxx/yyy <<EOF

set serveroutput on linesize 2000 feedback off
WHENEVER SQLERROR EXIT SQL.SQLCODE;

variable recordId number;

declare
    sql_ins      varchar (2000):='';
begin

    :recordId:=0;
    sql_ins:=q'{insert into xxx values (yyy)}';

execute immediate sql_ins;

exception
             WHEN OTHERS then
                   :recordId:=SQLCODE;
end;
/
exit :recordId;

EOF

echo 'rc='$?
~