Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Using Database Trigger on Servererror to track all Oracle Errors
I want to create a trigger that writes to a table or file whenever an
Oracle error happens. The main thing I want to capture is the
offending SQL. Users are reporting these errors out of an application
erratically and we don't know the call that is causing the error.
Does anyone know how to catch the offending SQL? How about capturing any error message code - as in SQLCODE or SQLERRM which always seems to be 0.
Here is a code sample. The pl/sql will run however I can't capture what I am really interested in.
create or replace trigger log_all_servererrors after servererror
on database
declare
v_output utl_file.file_type; v_sqlcode varchar2(250); v_sqlerrm varchar2(250);
v_output := utl_file.fopen('C:\TEMP','log_all_servererrors.txt','a'); utl_file.put_line(v_output,'error has occurred'); utl_file.put_line(v_output,sysdate); /* this is where I want to put in the offending SQL */ utl_file.new_line(v_output); utl_file.fclose (v_output);