PL/SQL Trigger Structure

Triggers are fired on the tables or views which are in the database. Either table, view ,schema, or a database are the basic requirement to execute a trigger. The trigger is specified first and then the action statement are specified later.

Syntax:

CREATE OR REPLACE TRIGGER trigger_name

BEFORE or AFTER or INSTEAD OF //trigger timings

INSERT or UPDATE or DELETE // Operation to be performed

of column_name

on Table_name

FOR EACH ROW

DECLARE

Declaration section

BEGIN

Execution section

EXCEPTION

Exception section

END;

/

Query operation to be performed i.e INSERT,DELETE,UPDATE.

  • CREATE [ OR REPLACE ] TRIGGER trigger_name is used to create a trigger or replace the existing trigger.|
  • BEFORE | AFTER | INSTEAD OF specifies trigger timing.
  • INSERT | UPDATE | DELETE are the DML operations performed on table or views.
  • OF column_name specifies the column that would be updated.
  • ON table_name species the table for the operation.
  • FOR EACH ROW specify that trigger is executed on each row .

PL/SQL Triggers

PL/SQL stands for Procedural Language/ Structured Query Language. It has block structure programming features.PL/SQL supports SQL queries. It also supports the declaration of the variables, control statements, Functions, Records, Cursor, Procedure, and Triggers.PL/SQL contains a declaration section, execution section, and exception-handling section. Declare and exception handling sections are optional.

Syntax:

Declaration section

BEGIN

Execution section

EXCEPTION

Exception section

END;

Similar Reads

PL/SQL Triggers

PL/SQL triggers are block structures and predefined programs invoked automatically when some event occurs. They are stored in the database and invoked repeatedly in a particular scenario. There are two states of the triggers, they are enabled and disabled. When the trigger is created it is enabled. CREATE TRIGGER statement creates a trigger. A triggering event is specified on a table, a view, a schema, or a database.BEFORE and AFTER are the trigger Timing points.DML triggers are created on a table or view, and triggers. Crossedition triggers are created on Edition-based redefinition. System Triggers are created on schema or database using DDL or database operation statements.It is applied on new data only ,it don’t affect existing data....

Why are Triggers important?

The importance of Triggers are:...

PL/SQL Trigger Structure

Triggers are fired on the tables or views which are in the database. Either table, view ,schema, or a database are the basic requirement to execute a trigger. The trigger is specified first and then the action statement are specified later....

Types of PL/SQL Triggers

Trigger timing and operations forms different combinations such as BEFORE INSERT OR BEFORE DELETE OR BEFORE UPDATE .BEFORE and AFTER are known as conditional triggers....

Common Use Cases of PL/SQL Triggers

To automate the actions in response to the events and reducing manual task. To apply constraint to ensure referential integrity and to prevent invalid data in table or database. In error handling to response to errors....

Conclusion

In conclusion, Oracle PL/SQL triggers offer a powerful way to automate actions before or after specified events, such as INSERT, UPDATE or DELETE, on a table. By executing custom code, handling exceptions, and enforcing business rules, triggers improve database performance and data integrity....

Contact Us