PL/SQL User's Guide and Reference Release 2 (9.2) Part Number A96624-01 |
|
PL/SQL Language Elements, 50 of 52
The function SQLERRM
returns the error message associated with its error-number argument or, if the argument is omitted, with the current value of SQLCODE
. SQLERRM
with no argument is meaningful only in an exception handler. Outside a handler, SQLERRM
with no argument always returns the message normal, successful completion.
For internal exceptions, SQLERRM
returns the message associated with the Oracle error that occurred. The message begins with the Oracle error code.
For user-defined exceptions, SQLERRM
returns the message user-defined exception unless you used the pragma EXCEPTION_INIT
to associate the exception with an Oracle error number, in which case SQLERRM
returns the corresponding error message. For more information, see "Retrieving the Error Code and Error Message: SQLCODE and SQLERRM".
This must be a valid Oracle error number. For a list of Oracle errors, see Oracle9i Database Error Messages.
SQLERRM
is especially useful in the OTHERS
exception handler because it lets you identify which internal exception was raised.
You can pass an error number to SQLERRM
, in which case SQLERRM
returns the message associated with that error number. The error number passed to SQLERRM
should be negative. Passing a zero to SQLERRM
always returns the following message:
ORA-0000: normal, successful completion
Passing a positive number to SQLERRM
always returns the message
User-Defined Exception
unless you pass +100
, in which case SQLERRM
returns the following message:
ORA-01403: no data found
You cannot use SQLERRM
directly in a SQL statement. First, you must assign the value of SQLERRM
to a local variable, as follows:
my_sqlerrm := SQLERRM; ... INSERT INTO errors VALUES (my_sqlerrm, ...);
When using pragma RESTRICT_REFERENCES
to assert the purity of a stored function, you cannot specify the constraints WNPS
and RNPS
if the function calls SQLERRM
.
In the following example, the string function SUBSTR
ensures that a VALUE_ERROR
exception (for truncation) is not raised when you assign the value of SQLERRM
to my_sqlerrm
:
DECLARE my_sqlerrm VARCHAR2(150); ... BEGIN ... EXCEPTION ... WHEN OTHERS THEN my_sqlerrm := SUBSTR(SQLERRM, 1, 150); INSERT INTO audits VALUES (my_sqlerrm, ...); END;
|
Copyright © 1996, 2002 Oracle Corporation. All Rights Reserved. |
|