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!

Trigger to update a column with the sum value from other table column

2677460Sep 9 2014 — edited Sep 9 2014

Hi Experts,

my requirement is following.

I have the following tables


ACCOUNT                                                  EXPENSE                                        Person                                Config

Acc_id(pk)                                                   Exp_id(pk)                                        person_id(pk)                       id

Acc_type_id   (fk to a config table)                  exp_type_id (fk to config table)            name                                 description                                                                             

Contribution                                                  Amount                                                                                        value                                                  

person_id (Fk to Person)                                person_id (fk to person)                                                                                           

My requirement is to create a trigger which will update the amount column of  expense for a particular exp_type_id with the sum values of contributions from account for some acc_type_id.The update statement is as follows

update expense se

set se.amount=(select sum(sa.contributions)  from account sa

where sa.account_type in (54,57,58)

and sa.person_id=se.person_id)

where se.expense_item_id=2

and se.person_id=3

I have hardcoded the person_id for testing.but this person_id should be a variable

I need to create a trigger to implement this.Please help

Regards,

Aparna

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 7 2014
Added on Sep 9 2014
5 comments
2,175 views