I generally work with both solutions:
-----> Use: "WHENEVER SQLERROR EXIT 1" (as commented by Carlo)
-----> Redirect SQLPLus' output to a file and validate the error.
-----> Also use: "sqlplus -S -L" to try to login just once.
sqlOutputFile="./sqlplusExec.log"
# sqlplus -S -L PASS/USERID@DB << EOF > "${sqlOutputFile}"
WHENEVER SQLERROR EXIT 1
SELECT * from notable;
EOF
sqlplusRetCode=${?}
countErrors=`egrep -c 'ORA-[0-9]{4}|SP2-|TNS-|Usage' "${sqlOutputFile}"`
if [ ${sqlplusRetCode} -ne 0 -o ${countErrors} -ne 0 ]
then
echo "Found errors while executing SQLPlus[${sqlplusRetCode}][${countErrors}]: "
egrep 'ORA-[0-9]{4}|SP2-|TNS-|Usage' "${sqlOutputFile}"
exit 1
fi