Is there a way to get the SQL statement which fired the trigger, inside the trigger block ?
Say, I issue the following statement,
-----------------------------------------------
SQL> update scott.emp set sal = 0 ; -- Statement which fires trigger
SQL> commit;
Which fires the the following trigger,
----------------------------------------------
create or replace trigger scott.test_trigger
before update on scott.emp
begin
/*Code to store the SQL statement which fired the trigger */
insert into EMP_UPDATE_SQLS values ( **TRIGGERING_SQL_STMT** );
end;
Result expected:
---------------------
A row in EMP_UPDATE_SQLS , with the sql statement that fired the trigger, ( a row with the value 'update scott.emp set sal = 0' ).
Re: Getting the triggering statement inside a trigger
Originally posted by ramesh_1600 Is there a way to get the SQL statement which fired the trigger, inside the trigger block ?
Say, I issue the following statement,
-----------------------------------------------
SQL> update scott.emp set sal = 0 ; -- Statement which fires trigger
SQL> commit;
Which fires the the following trigger,
----------------------------------------------
create or replace trigger scott.test_trigger
before update on scott.emp
begin
/*Code to store the SQL statement which fired the trigger */
insert into EMP_UPDATE_SQLS values ( **TRIGGERING_SQL_STMT** );
end;
Result expected:
---------------------
A row in EMP_UPDATE_SQLS , with the sql statement that fired the trigger, ( a row with the value 'update scott.emp set sal = 0' ).
Is it possible ???
Yes.
If you compare the fields between the :OLD and :NEW meta rows. the columns that are different are the ones that changed, assuming an update statement.
Settled with solution which is similar to the one that Padders had posted. I was trying to use the v$sqlarea, to get the current sql statement ( most probably the statement which fires the trigger ), but Padders' solution was smarter.
Bookmarks