Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Inserting an aggregation from a table on a trigger into another table

Richard LeggeDec 2 2014 — edited Dec 5 2014

Hi All.

XE 11.2

As a follow on from yesterdays question. I'm trying to create a trigger on a table that sums values in the table including existing ones and new one, then populates a summary table with this value.

For example, in the main table I have a number of records  with a matching code and a value  i.e. 

( ID,CODE,VALUE)

(1,'AAA',1234.56)

(2,'AAA',2213.45). 

When I insert a new record that matches the CODE (AAA), the trigger sums the existing values, as well as the newly inserted value, and then updates/inserts into an aggregation table with the code and sum of the 3 values.

My Question is whether this is possible? i.e. can I do a query on the table as part of an after insert/update, and will it sum correctly, or will it give me a mutating table error?  If the latter, (and Im just going to try this), can anyone suggest alternatives.. (I can't create views or materialized views, because another table will also be inserting into the aggregate table...)

Kind Regards

Richard

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 2 2015
Added on Dec 2 2014
13 comments
3,054 views