SQLCODE

The SQLCODE is also set by Db2 after each SQL statement is executed.

Db2 conforms to the SQL standard as follows:

  • If SQLCODE = 0 and SQLWARN0 is blank, execution was successful.
  • If SQLCODE = 100, "no data" was found. For example, a FETCH statement returned no data because the cursor was positioned after the last row of the result table.
  • If SQLCODE > 0 and not = 100, execution was successful with a warning.
  • If SQLCODE = 0 and SQLWARN0 = 'W', execution was successful with a warning.
  • If SQLCODE < 0, execution was not successful.

In the case of a LOOP statement, the SQLSTATE is set after the END LOOP portion of the LOOP statement completes. With the REPEAT statement, the SQLSTATE is set after the UNTIL and END REPEAT portions of the REPEAT statement completes.

The SQL standard does not define the meaning of any other specific positive or negative values of SQLCODE, and the meaning of these values is not the same in all implementations of SQL.

If the application is using Db2 ODBC, an SQLCODE is only returned if the application issues the SQLGetSQLCA function.