PL/SQL Trigger 2 – BEFORE and AFTER INSERT Trigger

BEFORE INSERT Trigger

A BEFORE INSERT Trigger means that Oracle will fire this trigger before the INSERT operation is executed.

The syntax for an BEFORE INSERT Trigger is:

CREATE or REPLACE TRIGGER trigger_name
BEFORE INSERT
   ON table_name
   [ FOR EACH ROW ]

DECLARE
   — variable declarations

BEGIN
   — trigger code

EXCEPTION
   WHEN …
   — exception handling

END;

Restrictions

    * You can not create a BEFORE trigger on a view.
    * You can update the :NEW values.
    * You can not update the :OLD values.

AFTER INSERT Trigger
    
An AFTER INSERT Trigger means that Oracle will fire this trigger after the INSERT operation is executed.

The syntax for an AFTER INSERT Trigger is:

CREATE or REPLACE TRIGGER trigger_name
AFTER INSERT
   ON table_name
   [ FOR EACH ROW ]

DECLARE
   — variable declarations

BEGIN
   — trigger code

EXCEPTION
   WHEN …
   — exception handling

END;

Restrictions

    * You can not create an AFTER trigger on a view.
    * You can not update the :NEW values.
    * You can not update the :OLD values.

 


 

You can leave a response, or trackback from your own site.

Leave a Reply