PL/SQL Triggers in Oracle

PL/SQL Triggers

A PL/SQL trigger is a construct in PL/SQL that runs or "triggered" on event of changes being made to a table in the database. The triggering event is a INSERT, UPDATE or DELETE done on a table. The trigger can be made so it can be "fired" either BEFORE or AFTER the Data Manipulation Language is executed.

  • A database trigger is a block of code that is automatically executed in response to certain events.
  • Triggers are executed implicitly whenever the triggering event happens.
  • The triggering event is an INSERT, DELETE, or UPDATE command.
  • The timing can be either BEFORE or AFTER, INSTEAD OF trigger.

The trigger can be either row-level or statement-level, where the former fires once for each row affected by the triggering statement and the latter fires once for the whole statement.

You can write triggers that fire whenever one of the following operations occurs:

  1. DML statements (INSERT, UPDATE, DELETE) on a particular table or view, issued by any user

  2. DDL statements (CREATE or ALTER primarily) issued either by a particular schema/user or by any schema/user in the database

  3. Database events, such as logon/logoff, errors, or startup/shutdown, also issued either by a particular schema/user or by any schema/user in the database

A trigger has three basic parts:

  • A triggering event or statement
  • A trigger restriction
  • A trigger action

No comments:

Post a Comment

Please Provide your feedback here