0% found this document useful (0 votes)
25 views7 pages

Triggers

A trigger is a named PL/SQL block stored in a database that is automatically executed in response to certain events on a table or view. Triggers can be defined to fire before or after a data manipulation language (DML) statement such as insert, update or delete. Triggers can be row-level, firing once for each row affected by the triggering statement, or statement-level, firing once regardless of the number of rows affected.

Uploaded by

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

Triggers

A trigger is a named PL/SQL block stored in a database that is automatically executed in response to certain events on a table or view. Triggers can be defined to fire before or after a data manipulation language (DML) statement such as insert, update or delete. Triggers can be row-level, firing once for each row affected by the triggering statement, or statement-level, firing once regardless of the number of rows affected.

Uploaded by

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

What Triggers are

1.

Trigger is a named PL/SQL block stored in a database


and executed implicitly when a triggering event occurs.

2.

Triggering event is a DML statement executed against


database table.

3.

Trigger can fire before or after a triggering event.

Trigger
The general syntax for creating a trigger
Is as follows
Create [ or replace ] trigger trigger_name
{BEFORE|AFTER} triggering_event ON table_name
[FOR EACH ROW]
[WHEN Condition]
DECLARE
Declaration statements
BEGIN
Executable statements
EXCEPTION
Exception Handling statements
END;

Triggers
Types of Triggers
The following are the different types of triggers.
Row triggers
and statement triggers
1. A Row trigger fires once for each row affected. It uses
FOR EACH ROW clause.
2. Statement Trigger fires once, irrespective of number of
rows affected in the table.

Triggers
Before and afterTriggers
While defining the trigger we can specify whether to
perform the trigger action (i.e. execute trigger body)
before or after the triggering statement. BEFORE and
AFTER triggers fired by DML statements can only be
defined on tables.
BEFORE triggers The trigger action here is run
before the trigger statement.
AFTER triggers The trigger action here is run after
the trigger statement.

Triggers

Desc user_triggers;
Select * from user_triggers;

Triggers
create or replace trigger mytrigger1
before insert or delete or update on emp
for each row
begin
if to_char(sysdate,'day') = 'SUN' then
dbms_output.put_line('today is holiday');
else
dbms_output.put_line('welcome back');
end if;
end;
.
Trigger created.

Triggers
SQL> update emp set salary='10000' where empid='a1';
welcome back
1 row updated.

SQL>insert into emp values('a5','anik','20000','pune','pune');


welcome back
1 row created.

You might also like