I'm handling a PL/SQL package containing a {FORALL .. SAVE EXCEPTIONS .. UPDATE} statement.
The validity of the data (to the business rules) is checked with a trigger on the table with the data that will be updated. This trigger calls a procedure that is able to generate an error using:
RAISE_APPLICATION_ERROR( -20002, 'message');
It is thus possible to generate a user defined error during the {FORALL .. SAVE EXCEPTIONS .. UPDATE} DML statement. However, when attempting to log the error in the exception handling using the SQL%BULK_EXCEPTIONS I observe the following output;
SQLCODE: ORA-24381
SQLERRM: ORA-24381: error(s) in array DML
SQL%BULK_EXCEPTIONS(i).ERROR_CODE: 20002
SQLERRM(-(SQL%BULK_EXCEPTIONS(i).ERROR_CODE)): ORA-20002:
Note that the error_code from the sql%bulk_exceptions loses the minus-sign. Also the error message is empty save for the error's code.
There are 2 problems for me here:
- The (user defined) error's message is not returned through the bulk_exceptions. (This is not the case for standard errors! f.e.: would the FORALL-UPDATE fail because of a column size constrain, the error message from bulk_exceptions could be: "ORA-12899: value too large for column", and will not be empty.)
- When this exception is raised, the SQLCODE+SQLERRM "ORA-24381: error(s) in array DML" are passed through, instead of the actual triggered (user defined, -20000) error code and message.
Is it possible to tie the message from RAISE_APPLICATION_ERROR to the user defined error code so that SQLERRM will show it? And how can I propagate this error without it changing to the ORA-24381 error?