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