0% found this document useful (0 votes)
29 views

Creating Triggers: Trigger

Triggers are stored database procedures that are implicitly invoked by Oracle when a triggering event occurs, such as a DML statement like INSERT, UPDATE, or DELETE on a table. Triggers can be defined to fire before or after these events on the table, view, schema, or database that the event is associated with. The syntax to create a trigger includes specifying the trigger name, the triggering event, the table or view it is associated with, and the PL/SQL block with the logic to execute in response to the event.

Uploaded by

priya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Creating Triggers: Trigger

Triggers are stored database procedures that are implicitly invoked by Oracle when a triggering event occurs, such as a DML statement like INSERT, UPDATE, or DELETE on a table. Triggers can be defined to fire before or after these events on the table, view, schema, or database that the event is associated with. The syntax to create a trigger includes specifying the trigger name, the triggering event, the table or view it is associated with, and the PL/SQL block with the logic to execute in response to the event.

Uploaded by

priya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Trigger

Triggers are similar to stored procedures. A trigger stored in the database can include SQL and
PL/SQL or Java statements to run as a unit and can invoke stored procedures. However,
procedures and triggers differ in the way that they are invoked. A procedure is explicitly run by a
user, application, or trigger. Triggers are implicitly fired by Oracle when a triggering event
occurs, no matter which user is connected or which application is being used
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

Triggers could be defined on the table, view, schema, or database with which the event is
associated.

Creating Triggers
The syntax for creating a trigger is:
CREATE [OR REPLACE ] TRIGGER trigger_name
{BEFORE | AFTER | INSTEAD OF }
{INSERT [OR] | UPDATE [OR] | DELETE}
[OF col_name]
ON table_name
[REFERENCING OLD AS o NEW AS n]
[FOR EACH ROW]
WHEN (condition)
DECLARE
Declaration-statements
BEGIN
Executable-statements
EXCEPTION
Exception-handling-statements

End;

You might also like