Whenever I run a sql script using Sql*plus and check for $?, I get 0 even when the script wasn\'t succesful.
Example
#$ sqlplus user/password@instanc
You have to explicitly tell sqlplus to do that, in your script. Basically, there are two statements that you can use:
WHENEVER SQLERROR EXIT SQL.SQLCODEWHENEVER OSERROR EXITFor example:
WHENEVER SQLERROR EXIT SQL.SQLCODE
begin
SELECT COLUMN_DOES_NOT_EXIST FROM DUAL;
END;
/
And for OS errors:
WHENEVER OSERROR EXIT FAILURE
START no_such_file
For more information, see this and that.
Hope it helps. Good Luck!