Prepare for your Next Interview
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? ...
|
|||
|
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 |
| Sponsored Links |
|
|||
|
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;
|
|
|||
|
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 |
|
|||
|
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. |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| 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 |