Download PL/SQL User's Guide and Reference
Transcript
SQLERRM Function
Example
The following example retrieves the error message associated with an unhandled
exception, and stores it in an audit table. The SUBSTR function truncates the message if
it is too long to fit in the table.
CREATE TABLE errors (code NUMBER, message VARCHAR2(128), happened TIMESTAMP);
DECLARE
name employees.last_name%TYPE;
my_code NUMBER;
my_errm VARCHAR2(32000);
BEGIN
SELECT last_name INTO name FROM employees WHERE employee_id = -1;
EXCEPTION
WHEN OTHERS THEN
my_code := SQLCODE;
my_errm := SQLERRM;
dbms_output.put_line('Error code ' || my_code || ': ' || my_errm);
-- Normally we would call another procedure, declared with PRAGMA
-- AUTONOMOUS_TRANSACTION, to insert information about errors.
INSERT INTO errors VALUES (my_code, my_errm, SYSTIMESTAMP);
END;
/
DROP TABLE errors;
Related Topics
Exceptions, SQLCODE Function
PL/SQL Language Elements 13-137
Related documents
PL/SQL User's Guide and Reference
Oracle Database PL/SQL User's Guide and Reference
PL/SQL User's Guide and Reference, Release 8.0
SQL*Loader Control File
A Software Application for a Car Sales and Servicing
Automated bookmark management
Migration Center User`s Manual
Peg Perego Prima Pappa Diner User's Manual
ソフトウェア工学
What is iSQL*Plus? - Oracle Documentation
Database Link User`s Manual