SQLSTATE special value

SQLSTATE indicates whether the most recently executed SQL statement resulted in a success, error, or warning condition.

Data type

String

Remarks

The database server sets a SQLSTATE and SQLCODE for each SQL statement it executes. A SQLSTATE is a string that indicates the whether the most recently executed SQL statement resulted in a success, warning, or error condition.

Each SQLSTATE represents errors that are common to all platforms, and usually contain non-product-specific wording. The format of a SQLSTATE value is a two-character class value, followed by a three-character subclass value. Guidelines for SQLSTATE conformance with regard to class and subclass values are outlined in the ISO/ANSI SQL standard.

SQL Anywhere conforms to the ISO/ANSI SQLSTATE conventions with the following additions and exceptions:

Class and subclass Condition
01WCx Warnings related to character set conversion
38xxx External function exception
42Xxx Syntax error: expressions
42Rxx Syntax error: referential integrity (for example, attempt to create 2nd primary key)
42Wxx Syntax error: generic
42Uxx Syntax error: duplicate, undefined, or ambiguous object reference
42Zxx Access violation
54Wxx Product limit exceeded
55Wxx Object not in required state for operation to succeed
57xxx Resource not available or operator intervention
5Rxxx SQL Remote errors
WBxxx Online backup errors
WIxxx Internal database errors
WPxxx Errors in procedures, variables, and so on
WLxxx Errors loading and/or unloading
WWxxx Miscellaneous SQL Anywhere-specific errors/warnings (including system failures)
WOxxx Remote data access feature-related errors
WJxxx JCS and JDBC related errors
WCxxx Character translation errors
WXxxx XML-related errors
WTxxx Text-related errors

The successful completion class is '00xxx' (for example, '00000').

SQLSTATE and SQLCODE are related in that each SQLCODE corresponds to a SQLSTATE, and each SQLSTATE can correspond to one or more SQLCODEs.

To return the error condition associated with a SQLSTATE, you can use the ERRORMSG function. See ERRORMSG function [Miscellaneous].

To see the SQLSTATE values used by SQL Anywhere, see SQL Anywhere error messages sorted by SQLSTATE.

See also
Standards and compatibility
  • SQL/2003: core feature   SQLSTATE classes (the first two characters) beginning with the values '0'-'4', and 'A'-'H' are defined by the ANSI standard. Other classes are implementation-defined. Similarly, subclass values that begin with values '0'-'4', and 'A'-'H' are defined by the ANSI standard. Subclass values outside these ranges are implementation-defined.