Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Using the Avg() function
Jeff Boyer wrote:
>
> I understand how to use the Avg() function but how would I go about using it
> in a trigger so that when a column is updated it calculates the average of
> that column but only for the records with the same primary key ans the
> record being updated. This is what I have for a trigger so far:
>
> CREATE OR REPLACE TRIGGER Score
> BEFORE INSERT on Phase2_5Ans
> FOR EACH ROW
> DECLARE
> Temp varchar2(30);
> BEGIN
> Select Avg(Score) from Phase2_5Ans where ??? into temp from dual;
> :New.TotalScore := Temp;
> End;
> /
>
> Can anyone help me?? I know there is a simple solution to my problem I just
> don't know how to pass a variable to the where clause.
>
> Thanks again,
> Jeff
Your 'where' would be:
where primary_key_col = :new.primary_key_col
you will then probably encounter a mutating table error which if you search archives on this group you can get a solution
hth
connor
-- ============================== Connor McDonald http://www.oracledba.co.uk "Some days you're the pigeon, some days you're the statue..."Received on Fri Sep 07 2001 - 12:56:53 CDT
![]() |
![]() |