Skip to content
DB2 & data

SQLCODE

The result code DB2 returns after every SQL statement, saying whether it worked and what happened if it did not.

Also written SQLSTATE, SQL return code

After every SQL statement, DB2 sets a code the program can examine. Checking it is not optional in well-written code. It is how the program knows whether the data it is about to use is real.

The scheme is simple. Zero means the statement succeeded. A positive value means it succeeded with something you should know about, the most important being the code meaning no row was found, which is how a program discovers a customer does not exist or a cursor has run out of rows. A negative value means the statement failed.

Alongside it sits SQLSTATE, a standardised code that means the same thing across different database products.

Handling matters. A program that fetches into a field without checking the code will happily process whatever was in that field before, and the failure surfaces much later as bad data rather than as an error. Most sites have a standard routine that checks the code after every operation and abends with a clear message if it is unexpected.

Reading these codes is a daily activity in application support.

Browse all 115 terms

Learn this properly.

Use SQLCODE for real in Mainframe101, in your browser, with Zed beside you. Join the waitlist.

Early access and updates. No spam, unsubscribe any time.