AFTER INSERT TRIGGER
634773Apr 20 2010 — edited Apr 20 2010I have an after insert trigger that calls a procedure that recreates a view using pragma AUTONOMOUS TRANSACTION and execute immediate. This view does not reference to the same table but to another table that is recreated after the insert. The trigger seems to work only after the first insert. I have added another execute immediate in the same procedure that inserts some dummy data to another table not used by the view I am recreating to validate that the procedure is executed whenever the trigger is fired. I am wondering why it doesn't work for the first insert.
Here's an example of my trigger:
CREATE OR REPLACE TRIGGER TRIGGER_AFT
AFTER INSERT
ON SOME_TABLE
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
BEGIN
INSERT INTO ANOTHER_TABLE (TYPE, COUNT) VALUES (TO_CHAR(SYSDATE), TO_CHAR(SYSDATE));
recreate_view;
EXCEPTION
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
END TRIGGER_AFT;
PROCEDURE recreate_view
IS
pragma AUTONOMOUS_TRANSACTION;
BEGIN
execute immediate 'DROP TABLE SOME_TABLE_COPY;
commit;
execute immediate 'create table SOME_TABLE_COPY as select * from SOME_TABLE';
commit;
execute immediate 'INSERT INTO ANOTHER_TABLE (TYPE, COUNT) VALUES (''TEST2'', ''TEST2'')';
commit;
END recreate_view;