PL supports two error-reporting functions: SQLCODE and SQLERRM, which can be used in PL's exception handling code. These functions can be used on exception handling code of PL.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition provides only the MySQL mode.
Notice
The SQLCODE and SQLERRM functions cannot be used in SQL statements.
SQLCODE function
In an exception handler, SQLCODE returns the error code corresponding to the exception being handled. Outside an exception handler, SQLCODE always returns 0.
For an internally defined exception, the numeric code is associated with the code of the database error.
For a user-defined exception, the numeric code is the default value +1 or the error code associated with an exception of the EXCEPTION_INIT compilation directive.
The syntax is as follows:
SQLCODE
SQLERRM function
SQLERRM returns the error message associated with an error code.
The syntax is as follows:
SQLERRM [ ( error_code ) ]
In the syntax, error_code is optional. If no error code is available, this function returns the error message corresponding to the current value of the SQLCODE function.