I would like to catch any sql error that could happen so I wrote this in the ksh :
$ORACLE_HOME/bin/sqlplus -s u/p <<EOF
WHENEVER OSERROR EXIT 68;
WHENEVER SQLERROR EXIT SQL.SQLCODE;
CREATE TABLE new_table
AS (SELECT * FROM wrong_old_table);
COMMIT;
EOF
I put a wrong name for the old table to see what happens. I expect to have the sqlcode only like I ask in WHENEVER SQLERROR but I have this :
AS (SELECT * FROM wrong_old_table)
*
ERROR at line 2:
ORA-00942: table or view does not exist
I changed the code :
$ORACLE_HOME/bin/sqlplus -s u/p <<EOF
WHENEVER OSERROR EXIT 68;
WHENEVER SQLERROR EXIT SQL.SQLCODE;
BEGIN
CREATE TABLE new_table
AS (SELECT * FROM wrong_old_table);
COMMIT;
END;
EOF
sql_code=$?
echo "code=$sql_code"
Even though there is an error, the code equals 0. Where is the sql error code ?