Geeks Talk

Prepare for your Next Interview




Statement level triggers

This is a discussion on Statement level triggers within the Oracle forums, part of the Databases category; Hi I know row level triggers are used for maintaining history files. In application development where do we use statement level triggers? Can anyone give one good example for it? ...


Go Back   Geeks Talk > Databases > Oracle

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 03-02-2008
Contributing Member
 
Join Date: Mar 2008
Posts: 81
Thanks: 14
Thanked 3 Times in 3 Posts
babi_geek is on a distinguished road
Statement level triggers

Hi


I know row level triggers are used for maintaining history files. In application development where do we use statement level triggers? Can anyone give one good example for it?

Regards
Babi
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-03-2008
Expert Member
 
Join Date: Apr 2007
Location: Bangalore
Posts: 447
Thanks: 20
Thanked 54 Times in 54 Posts
susarlasireesha is on a distinguished road
Re: Statement level triggers

Statement-level trigger fires once per triggering statement regardless of the number of rows affected by the triggering event. Create table employeeaudit ( dt date, usr varchar2(20), action varchar2(50) ); create or replace trigger employee_audit after insert or update or delete on emp declare action varchar2(50); begin if inserting then action := 'new emp record is add'; elsif updating then action := 'emp record is updated'; elsif deleting then action := 'emp record is deleted'; end if; insert into employeeaudit values (sysdate, user,action); end; drop table employeeaudit;
Reply With Quote
  #3 (permalink)  
Old 03-03-2008
Expert Member
 
Join Date: Apr 2007
Location: Bangalore
Posts: 447
Thanks: 20
Thanked 54 Times in 54 Posts
susarlasireesha is on a distinguished road
Re: Statement level triggers

Statement-level trigger fires once per triggering statement regardless of the number of rows affected by the triggering event.

Create table employeeaudit ( dt date,
usr varchar2(20),
action varchar2(50) );


create or replace trigger employee_audit
after insert or update or delete on emp
declare action varchar2(50);
begin
if inserting then action := 'new emp record is add';
elsif updating then action := 'emp record is updated';
elsif deleting then action := 'emp record is deleted';
end if;
insert into employeeaudit values (sysdate, user,action);
end;

drop table employeeaudit
Reply With Quote
  #4 (permalink)  
Old 03-03-2008
Junior Member
 
Join Date: Feb 2008
Location: Edinburgh
Posts: 21
Thanks: 3
Thanked 2 Times in 2 Posts
su123 is on a distinguished road
Re: Statement level triggers

Create table entity_x
( a varchar2(20), b number(10), c date);
here we are creating a trigger;
create or replace trigger statement_level
before update on entity_x
declare vmessage varchar2(30) := 'statement level trigger is fired';
begin
dbms_output.put_line(vmessage);
end statement_level;
/
set serveroutput on
insert into entity_x (a) values ('name1');
update entity_x set a = 'name2';

Imp Note: Here we are having before and after in triggers, means we are giving instruction to that when it should perform the action, In detail: Before means before compiling the statement the trigger will be fired, After means After the compilation The trigger will be fired

when you are executing this particular statement, the pl/sql compiler will detect that it is having update condition so it will check whether any trigger is there for update command for this particular entity, so here we are having a trigger related with it, so it will show you the message what you had given there, here i gave the message 'statement level trigger is fired'. You can use not only (dbms_output.put_line), also you can use anonymous blocks or you can call procedures to perform an action what ever you want at that place, here the anonymous blocks are more affective.
'susarlasireesha' also given a good example, u can try what i gave for you, after that u try the another, what she had given is a multitasking trigger. So u can see the difference.

Last edited by su123 : 03-03-2008 at 06:02 AM.
Reply With Quote
Reply

  Geeks Talk > Databases > Oracle


Thread Tools
Display Modes


Similar Threads

Thread Thread Starter Forum Replies Last Post
Why we have to close connection, statement, prepared statement Geek_Guest Java 8 02-27-2008 07:09 AM
Can Select statement be used along with Update statement? pankit SQL 2 01-10-2008 06:30 AM
2 high level and 2 low level design techniques Geek_Guest Testing Issues 0 06-25-2007 05:52 AM
About Report Triggers JobHelper Oracle 3 01-09-2007 08:01 AM
Triggers Types scott SQL 1 07-30-2006 07:18 PM


All times are GMT -4. The time now is 08:50 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved