The Oracle (tm) Users' Co-Operative FAQ

How do I get the return code (or exit code) from SQL*Plus to a UNIX variable ?


Author's name: David T. Bath

Author's Email: David.Bath@edipost.auspost.com.au

Also once known as dtb@otto.bf.rmit.edu.au or orafaq@bf.rmit.edu.au

Date written: 9th Aug 2001

Oracle version(s): 8.1.7

How do I get the return code (or exit code) from SQL*Plus to a UNIX variable ?

Back to index of questions


Yes and No.

In sh variants, the exit code is available through $?

While SQL*Plus ATTEMPTs to put the Oracle error number into this value, this usually gets mod-ded by 256 or some such power of two, depending on your Unix dialect. A return of zero therefore means:....

	a) It was really zero, and everything OK
	b) ORA-256, ORA-512, .... or something like that was the problem.

The real solution is to trap the textual output of the error through stderr, slurp and mangle it and then backtick the results into a variable.  This may even be better, as you get the facility, which MIGHT be ORA, but might be something else entirely such as NET.


Further reading: N/A


Back to top

Back to index of questions