The Oracle SQLERRM function returns the error message associated with
the most recently raised error exception. The Oracle SQLERRM function
should only be used within the Exception Handling section of your
PL/SQLcode:
The Oracle docs note the syntax for the Oracle SQLERRM function as
follows:
sqlerrm_function ::=SQLERRM [(error_number)]
You can capture error codes
caused when a SQL statement raises an exception by using the Oracle SQLERRM
globally-defined variables Oracle
SQLERRM can help track exceptions that are handled by
the OTHERS clause of the exception handler.
Oracle SQLERRM returns the
error message from the current error code as shown below.
Here is a working Oracle SQLERRM example:

A value greater than 100 will raise an
exception using the same function from the previous example. The
exception handler caught the OTHERS clause and printed out the Oracle SQLERRM.
Once error code has been identified, you can programmatically handle the
exception:
Oracle SQLERRM example 2:
