DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: problem with trigger mutation

  1. #1
    Join Date
    Jan 2003
    Location
    india
    Posts
    175

    problem with trigger mutation

    hi,

    i have a table t1 with columns c1 and c2.

    i need to set the value of c2 based on the value of c1.
    so many applications are updating the column c1.
    the column c2 is newly added for some other applications.
    i can not modify all the old applications to update c2.

    i have a trigger on the table to update
    the column c2 if the value of column c1
    is changed.

    when i tried to update the column c1
    i am getting the error

    " ORA-04091 table string.string is mutating,
    trigger/function may not see it "

    copy of the trigger is

    create or replace trigger UpdateExpectedStock
    after insert or update on DrugControl
    referencing old as O new as N
    for each row
    begin

    update drugcontrol set ExpectedStock=
    ExpectedStock-(O.BalanceDrug - N.BalanceDrug)
    where Deptcode=O.DeptCode
    and TradeCode=O.TradeCode;
    end;


    can any body help to solve this problem.


    thanks in advance
    Raja
    Last edited by rajabalachandra; 09-11-2003 at 12:11 AM.

  2. #2
    Join Date
    Nov 2000
    Location
    Israel
    Posts
    268
    ORA-4091 Mutating Table Explanation and Workarounds:
    http://metalink.oracle.com/metalink/...T&p_id=74859.1
    It is better to ask and appear ignorant, than to remain silent and remain ignorant.

    Oracle OCP DBA 9i,
    C++, Java developer

  3. #3
    Join Date
    Apr 2003
    Location
    South Carolina
    Posts
    148
    Change your trigger to a before insert

    create or replace trigger UpdateExpectedStock
    BEFORE insert or update on DrugControl
    referencing old as O new as N
    for each row

    BEGIN

    ...
    IF updating('C1')
    then
    :N.ExpectedStock=
    ExpectedStock-(O.BalanceDrug - N.BalanceDrug)
    where Deptcode=O.DeptCode
    and TradeCode=O.TradeCode;
    end if;

    hth
    Gregg

  4. #4
    Join Date
    Jan 2003
    Location
    india
    Posts
    175

    i got it working

    hi

    i got it working.

    thank you gbrabham.

    thank you everybody

    -Raja

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width