Oracle Before INSERT/UPDATE/DELETE Trigger

This statement specifies that Oracle will fire this trigger BEFORE the INSERT/UPDATE or DELETE operation is executed.

Syntax

snippet
CREATE [ OR REPLACE ] TRIGGER trigger_name
BEFORE INSERT or UPDATE or DELETE
 ON table_name
  [ FOR EACH ROW ]
DECLARE
   -- variable declarations
BEGIN
   -- trigger code
EXCEPTION
   WHEN ...
   -- exception handling
END;

Parameters

OR REPLACE: It is an optional parameter. It is used to re-create the trigger if it already exists. It facilitates you to change the trigger definition without using a DROP TRIGGER statement.

trigger_name: It specifies the name of the trigger that you want to create.

BEFORE INSERT or UPDATE or DELETE: It specifies that the trigger will be fired before the INSERT or UPDATE or DELETE operation is executed.

table_name: It specifies the name of the table on which trigger operation is being performed.

Limitations

  • BEFORE trigger cannot be created on a view.
  • You cannot update the OLD values.
  • You can only update the NEW values.

Oracle BEFORE Trigger Example

Consider, you have a "suppliers" table with the following parameters.

You can use the following CREATE TRIGGER query to create a BEFORE INSERT or UPDATE or DELETE Trigger:

Here the trigger name is "SUPPLIERS_T1" and it is fired BEFORE the insert or update or delete operation is executed on the table "suppliers".

Oracle Before Trigger



Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +