SQLCODE is a built-in context function (Oracle) or host variable (IBM Db2, Informix) that exposes the return code from the last SQL operation. A value of 0 indicates success, a positive value signals a warning, and a negative value represents an error. In Oracle PL/SQL, SQLCODE is primarily referenced inside EXCEPTION blocks to capture the exact error number so it can be logged, re-raised, or handled conditionally. The function only reflects the most recent SQL statement in the same session or call stack and resets after each new statement. Unlike SQLERRM, which returns the full error message, SQLCODE returns only the numeric code, making it ideal for programmatic branching. SQLCODE does not work in pure SQL; it is evaluated in procedural code or embedded SQL. Outside an error context, Oracle returns 0, while Db2 preserves the last status even when it is positive or warning. Because SQLCODE is vendor-specific, portable applications should favor the ANSI-standard SQLSTATE or GET DIAGNOSTICS where available.
SQLERRM, SQLSTATE, GET DIAGNOSTICS, EXCEPTION handling, RAISE_APPLICATION_ERROR, SQLCA
Oracle Database 6 (PL/SQL 1.0) and IBM DB2 2.3 (SQLCA)
It returns 0, indicating the last SQL statement completed without errors.
No. SQLCODE is evaluated only in procedural contexts like PL/SQL blocks or host languages with embedded SQL. Referencing it in standalone SQL raises an error.
SQLCODE provides just the numeric error code. SQLERRM returns the corresponding message text. Use SQLCODE for branching logic and SQLERRM for logging or user messages.
No. Those systems use the ANSI-standard SQLSTATE and GET DIAGNOSTICS for error handling. SQLCODE is specific to Oracle, Db2, and Informix.