Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 26th, 2005, 02:00 AM
DBStudent DBStudent is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 54 DBStudent User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 1 m 34 sec
Reputation Power: 5
Read the table data in trigger

Hi,

i have a table called Student

Name | Result
------|--------
AAAA |50
AAAA |60
BBBB |80
BBBB |90


an AFTER INSERT trigger is created for Student table. When ever there is a new record, this trigger will total up the result for the student.

For example, new record with Name AAAA and result 40 is inserted. so trigger will calculate the total for AAAA and return 150.

However the trigger return mutating table error instead (ORA-04091: table Student is mutating, trigger/function may not see it), since the trigger read the Student table itself.

So, how to get the result 150?

Thanks.

Reply With Quote
  #2  
Old March 27th, 2005, 03:27 PM
paulh1983 paulh1983 is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Dec 2004
Posts: 1,249 paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 14 h 18 m 20 sec
Reputation Power: 17
show me the code?

if the trigger is using the table that you are currently working on then u will get that error, you have to use :NEW and :OLD to do it or some other way!

but why would you wanna use trigger? do you just want an OUTPUT on the screen or what? i think procedure may be better

Reply With Quote
  #3  
Old March 27th, 2005, 07:48 PM
DBStudent DBStudent is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 54 DBStudent User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 1 m 34 sec
Reputation Power: 5
Quote:
Originally Posted by paulh1983
but why would you wanna use trigger? do you just want an OUTPUT on the screen or what? i think procedure may be better


I use trigger because whenever there is new record inserted, the trigger will calculate the total for the particular student, then pass the total amount to other database.

This line cause my trigger fail:
CURSOR studentRecord IS
SELECT result FROM student WHERE name='AAAA'


Thanks.

Reply With Quote
  #4  
Old March 28th, 2005, 02:40 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,907 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 3 Days 9 h 21 m 6 sec
Reputation Power: 279
If you need to
Quote:
calculate the total for the particular student, then pass the total amount to other database

Just set up a dblink between the two databases and create a view (or a materialized view with "refresh fast on commit" option if you need a better performance).
I dont' think a trigger is appropriate for your need.
Hope this helps.

Last edited by pabloj : March 28th, 2005 at 02:42 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Read the table data in trigger


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT