Trigger inserting updating deleting

The order of firing multiple triggers can be defined using the FOLLOWS statement.The FOLLOWS option is explained in the next section. The following code creates a test table and a compound trigger that fires for each timing point associated with insert, update and delete statements.

trigger inserting updating deleting-8

Placing the PLSQL_OPTIMIZER_LEVEL parameter to 3 will automate the code inline process.

PL/SQL Compound Triggers A compound trigger is a PL/SQL trigger that contains multiple actions that take place at different timing points.

The compound trigger body does not have an initialization block and thus no exception block.

All exceptions must be handled in the section that raised the exception.

ON orders DECLARE v Msg VARCHAR2(30) := 'Statement Level Trigger Fired'; BEGIN dbms_output.put_line(v Msg); END statement_level; / set serveroutput on INSERT INTO orders (somecolumn) VALUES ('ABC'); UPDATE orders SET somecolumn = 'XYZ'; ON orders DECLARE v Msg VARCHAR2(30) := 'Statement Level Trigger Fired'; BEGIN IF INSERTING THEN dbms_output.put_line(v Msg || ' When Inserting'); ELSIF UPDATING THEN dbms_output.put_line(v Msg || ' When Updating'); ELSIF DELETING THEN dbms_output.put_line(v Msg || ' When Deleting'); END IF; END statement_level; / BEGIN SELECT seq_t.

NEXTVAL INTO : FROM DUAL; dbms_output.put_line(: NEW.rid); END row_level; / INSERT INTO t (col) VALUES ('A'); INSERT INTO t (col) VALUES ('B'); INSERT INTO t (col) VALUES ('C'); SELECT * FROM t; ON orders FOR EACH ROW DECLARE v Msg VARCHAR2(30) := 'Row Level Trigger Fired'; BEGIN dbms_output.put_line(v Msg); END row_level; / set serveroutput on INSERT INTO orders (somecolumn) VALUES ('ABC'); INSERT INTO orders (somecolumn) VALUES ('ABC'); INSERT INTO orders (somecolumn) VALUES ('ABC'); SELECT * FROM orders; UPDATE orders SET somecolumn = 'XYZ'; dbms_output.put_line(v Msg Tags: , ,