When an error occurs in MySQL, the server returns two types of error values:
A MySQL-specific error code. This value is numeric. It is not portable to other database systems.
An SQLSTATE value. The value is a five-character string (for
'42S02'). The values are taken
from ANSI SQL and ODBC and are more standardized.
A message string that provides a textual description of the error is also available.
When an error occurs, the MySQL error code, SQLSTATE value, and message string are available using C API functions:
The first two characters of an SQLSTATE value indicate the error class:
'00' indicates success.
'01' indicates a warning.
'02' indicates “not
found.” This is relevant within the context of cursors
and is used to control what happens when a cursor reaches the
end of a data set. This condition also occurs for
SELECT ... INTO
retrieve no rows.
'02' indicates an exception.