I am using the below query to achieve this. On executing the query for creating a trigger its working fine, but its throwing an error when I insert something into the table on which the trigger is created.
create or replace trigger TESTTRIG
after insert
or update
or delete
on sourcetable
declare
v_text varchar2(1000);
v_mask varchar2(100);
cursor c1
is
select sql_text
from v$open_cursor
where sid = sys_context('USERENV','SID')
order by last_sql_active_time desc;
begin
v_mask := case
when inserting then 'INSERT +INTO +<TABLE_NAME>( |\()'
when updating then 'UPDATE +<TABLE_NAME> '
else 'DELETE( +FROM)? +<TABLE_NAME>( |$)'
end;
open c1;
loop
fetch c1
into v_text;
exit when c1%notfound;
if regexp_like(v_text,v_mask,'i')
then
insert into targettable('TIME_EXEC','SQL_TEXT') values (SYSDATE,v_text);
exit;
end if;
end loop;
close c1;
end TESTTRIG;
/.
I am getting a ORA-04098 on inserting anything into the "sourcetable" table.Please help.