I’m running several sql scripts from bash. I want to see the summery of ORA-errors before adding commit. Something like this:
#!/bin/bash
S_DB2_CONNECTOR=""
echo "My statement"
SQL_STM=$( echo "UPDATE ..." | sqlplus login/pass@bd );
echo "Output:"
echo "$SQL_STM"
echo "searching for errors...."
echo $LOG_VAR | grep "ORA"
echo "before commit"
wait 1000
echo "COMMIT;" | sqlplus -s login/pass@bd;
But this doesn’t work, because sqlplus session is broken and !SURPRISE! sqlplus added auto commit after SQL_STM execution.
How to parse sqlplus output for ORA-/ST-errors before commit? Preferable in this terminal screen.
Maybe I do not need bash for parsing and sqlplus can do it for me? (So the session state will be preserved).
if you want to rollback / do some extra stuff in the case of an ORA code, then do it all in the SQL*PLUS session.
i.e. run it as a script.
if you just want to signal to bash that a sql statement failed , you can just set as the first thing in sql*plus.
whenever sqlerror exit sql.sqlcode(orwhenever sqlerror (exit -1etc) instead (see here). This would stop on the first error and return to your schell script with an appropriate return code.you can nest blocks eg:
etc.
if you needed it to be interactive, you could do something like (dbms_alert)[http://docs.oracle.com/cd/B19306_01/appdev.102/b14258/d_alert.htm#CHDCFHCI]:
then in another session you can issue: