Thursday, September 25, 2014

Oracle: Handle error codes with sqlplus

Tom Kyte explains it here:
http://tkyte.blogspot.fr/2010/04/new-thing-about-sqlplus.html
  1. Start with
    set errorlogging on identifier toto
    delete from sperrorlog where identifier = 'toto'
    /
    
  2. Then use some sqlplus commands
  3. And terminate with
    col nb_errors new_value nb_errors
    select count(*) as nb_errors from sperrorlog where identifier = 'toto'
    /
    exit nb_errors
This allows for testings the return code of sqlplus in a bash / perl script.

NB: See http://ss64.com/ora/syntax-sqlplus.html for the sqlplus syntax