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.
Related terms
- Embedded SQLSQL statements written directly inside a COBOL program, marked off so they can be prepared before compiling.
- CursorA mechanism for stepping through a set of rows one at a time, when a query returns more than one result.
- DB2 for z/OSIBM's relational database on the mainframe, where a great deal of the world's banking and insurance data is stored.
- SQLThe language used to query and change relational data. The same SQL used everywhere else, running against mainframe tables.
- AbendAn abnormal end: a program stopping in an uncontrolled way rather than finishing and reporting a result.
- Production supportKeeping live systems running: diagnosing failures, fixing what broke, and getting the service back.