Exforsys.com
 
Home Tutorials Oracle 9i
 

Tutorial 14: Oracle 9i : Database Triggers

 

Tutorial 14: Oracle 9i : Database Triggers - Page 2

Page 2 of 2



 


Handling multiple situations


A trigger can be used to handle multiple situations as shown in the following example. By using conditional predicates UPDATING, INSERTING, or DELETING we can handle each situation.




CORRELATION NAMES


While using row triggers, the trigger action statement can access column values of the row that is being processed currently. This is done using correlation names. There exist two correlation names for every column of the table, one for the column old value and the other for its new value. We use qualifier NEW with column name for new values and qualifier OLD is used to refer old value of the column.


Example:


IF :new.sal < :old.sal THEN
……

The REFERENCING option is used to avoid name conflicts between correlation names and table names. For example if you are using a table by name new or old with field names say SNO, NAME (though it is a very rare situation) then the ambiguity arises. To avoid this we use REFERENCING option.



Mutating Table: is a table that is presently under modification by INSERT, UPDATE, or DELETE statement, or a table that has referential integrity constraint with DELETE CASCADE OPTION.


Constraining Table: is a table, which is to be read by triggering statement either directly or indirectly.




In the above example when we tried to delete a row using SQL statement (Mutating Table) , which fires AFTER DELETE trigger. The body of this trigger is having a select statement that tries to read the table. This operation is not allowed by oracle. Hence we received a runtime error and total action is rolled back by Oracle. (The row is not deleted)


Download Sample Code 1


Download Sample Code 2


Download Sample Code 3




First Page: Tutorial 14: Oracle 9i : Database Triggers


Read Next: Tutorial 15: Oracle 9i : Oracle Packages



 

 

Comments


juturik said:

  Yes.

This is very good site to beginers.

Thanx a lot
July 8, 2005, 6:45 am

maran said:

  It is really good place for a beginner to learn. This article would be very fruitful, if you could give a strategy to avoid the mutating issue.

Thanks for a wonderful basics.
August 24, 2005, 3:04 pm

kiranc said:

  Good and sufficient content
August 18, 2006, 11:17 pm

Skhan said:

  Hi,
Its a good place to begin with triggers. It provides solid funda. Please add the advanced info on triggers.
Thanks!
Sami
May 16, 2007, 4:33 am

shivam said:

  Nice, short and excellent description of triggers. Good for beginners. Writtern in easy and lucid language and good illustrations too.
May 17, 2007, 10:39 pm

shivam said:

  Nice description and good illustrations. Excellent for beginners.
May 17, 2007, 10:41 pm

bhanucs said:

  I find it very useful for beginners. THX
June 14, 2007, 1:03 am

koumi said:

  hi dis is the good way of learning course
June 28, 2007, 2:11 am

arulkumar said:

  hi trigger concepts r very good also easy and simple
August 3, 2007, 6:22 am

Murali_Vadoni said:

  It is really helpfull in refreshing the topic

Thanks
September 10, 2007, 6:42 am

AJAY K said:

  This Document is rally good.
September 17, 2007, 2:04 am

KayKay said:

  I was looking for some 1 minute intro to Triggers.....and I got it here the way I wanted.
December 2, 2007, 11:50 am

tharanath said:

  hi. this document is really good and excellent for beginners.....
April 29, 2008, 7:40 am

Prasad.Gandra said:

  Excellent Information for starters... Really easy to Understand
May 16, 2008, 12:02 am

mohan12 said:

  very nice,
but need to add more examples..
May 28, 2008, 7:36 am

Lokesh Devanga said:

  These is very Nice,
but i need some more Examples.
June 17, 2008, 1:33 am

Gayatri Mukherji said:

  Really its too good...Simple but descriptive
July 18, 2008, 2:28 am

lehroy said:

  hey this is good one for getting the conecpt as a beginner level
July 22, 2008, 1:26 pm

Ganesh said:

  Very easy to Understand instead of reading a chapeter in book
November 19, 2008, 6:41 am

Sajid said:

  Excellent Information for starters... Really easy to Understand
January 13, 2009, 3:45 am

Mukesh Patil said:

  It's Really Good Site for Begginer's to learn....
January 19, 2009, 2:49 pm

Vijay.R.H said:

  The info present above is very easy to understand ....! thanks.....!
January 27, 2009, 4:41 am

Zaman Ahmad said:

  This site is really good for understand.........thanks.......
January 30, 2009, 6:27 am

0 said:

  Its good but you should give more examples in detailed manner
February 5, 2009, 2:29 am

amit kumar said:

  how many triggers we can make once please tell me somebody
May 26, 2009, 1:58 pm

Mahendra said:

  Hi Amit,
Below are the trigger types,
1) Statement Level
2) System Level
3) Instead of Trigger
4) Row level Trigger

For row and statement level we will create triggers as,
Before and After statement and Row level

Regards,
Mahendra
July 16, 2009, 7:55 am

Paresh said:

  We can create any no. of trigger but the combination is 12 only.
EX. INSERT/UPDATE/DELETE
ROW/STATEMENT
AFTER/BEFORE
September 10, 2009, 11:36 am

Tony said:

  Can you have multiple conditions in the WHEN statement?

WHEN (x=x && y=y)
October 13, 2009, 4:02 pm

logu said:

  How to create a trigger for a column in particular table which accepts only capital letters?
October 21, 2009, 12:50 am

nakul kadam said:

  How to create trigger for a row which when deleted it's any one field (e.g. emp_no ) which is primary key, get inserted into another table ?
October 29, 2009, 11:52 am

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2009 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape