Is there a way to track at the database level, when a foreign key constraint is violated by any users in the database. In other words say for example I have a table A and table B, B is having a foreign key constraint which references parent A. There are hunderds of programs which touch table B, I want find out which program (and it's OSUSER) is getting the error "PARENT KEY NOT FOUND' ??
Thanks,
Neeraj
ops$tkyte@ORA9IR2> create table p ( x int primary key );
Table created.
ops$tkyte@ORA9IR2> create table c ( x references p );
Table created.
ops$tkyte@ORA9IR2>
ops$tkyte@ORA9IR2> create or replace trigger t_trigger
2 after servererror on database
3 declare
4 l_text ora_name_list_t;
5 l_n number;
6 begin
7 if ( is_servererror(2291) )
8 then
9 dbms_output.put_line( '--------------------' );
10 dbms_output.put_line( 'statment causing error: ' );
11 l_n := ora_sql_txt( l_text );
12 for i in 1 .. nvl(l_text.count,0)
13 loop
14 dbms_output.put_line( l_text(i) );
15 end loop;
16
17 dbms_output.put_line( 'error text: ' );
18 for i in 1 .. ora_server_error_depth
19 loop
20 dbms_output.put_line( ora_server_error_msg(i) );
21 end loop;
22 dbms_output.put_line( '--------------------' );
23 end if;
24 end;
25 /
Trigger created.
ops$tkyte@ORA9IR2> insert into c values ( 1 );
insert into c values ( 1 )
*
ERROR at line 1:
ORA-02291: integrity constraint (OPS$TKYTE.SYS_C006478) violated - parent key
not found
ops$tkyte@ORA9IR2> exec null;
--------------------
statment causing error:
insert into c values ( 1 )
error text:
ORA-02291: integrity constraint (OPS$TKYTE.SYS_C006478) violated - parent key
not found
--------------------
PL/SQL procedure successfully completed.
see:
</code> http://docs.oracle.com/cd/B10501_01/appdev.920/a96590/adg14evt.htm#998000 <code>
for a list of all functions you have available to you. And of course, you can get access to the v$ tables for more details about the session as well (the program name, etc...)