Re: table mutating error - how do i get the :old, :new values?

From: M Claver <m_at_mclaver.myweb.nl>
Date: Thu, 26 Jul 2001 21:19:23 +0200
Message-ID: <9jpprm$3j4$1_at_cyan.nl.gxn.net>


Change your trigger in a before update instead of after update. In an after update trigger the old value can not be references since the table is already updated.

MC
Udaya <udayasangeetha_at_hotmail.com> schreef in berichtnieuws 13108883.0107261100.20c3cec_at_posting.google.com...
> Hi,
>
> I am new to Oracle and I have recently started working on triggers. I
> have a trigger on update/delete on each row on table A, which (should)
> update(s) multiple records in the same table based on the :old and
> :new values of the record being updated, but I get the "table
> mutating" error. After reading few of the replies from this group for
> this "table mutating" error, I tried using the package to get around
> this problem and I was successful in getting the :old value while
> deleting and updating but could not get the :new value while updating.
>
> I saw the solutions for these 2 cases using packages,
>
> INSERT trigger or an UPDATE trigger where you only need access to the
> :new values
> DELETE trigger or an UPDATE trigger where you need to access the :old
> values
>
> But how do I get both :new and :old values in the update trigger?
> Here is the table structure,
>
> bb_relationship
> ----------------------
> element_id number(8)
> linked_element_id number(8)
> has_child number(1)
>
>
> Here is the trigger which explains what it is supposed to do,
> ----------------------------------------------------------------
> create or replace trigger change_has_child
> after update or delete on bb_relationship
>
> declare
> cnt number(2);
> begin
> SELECT count(*) INTO cnt
> FROM bb_relationship
> WHERE linked_element_id = :OLD.linked_element_id;
>
> IF UPDATING THEN
>
> UPDATE bb_relationship
> SET has_child = 1
> WHERE element_id = :NEW.linked_element_id
>
> IF cnt = 0 THEN
> UPDATE bb_relationship
> SET has_child = 0
> WHERE element_id = :OLD.linked_element_id
> END IF;
>
> ELSE /* deleting */
> IF cnt = 0 THEN
> UPDATE bb_relationship_old
> SET has_child = 0
> WHERE element_id = :OLD.linked_element_id
> END IF;
> END IF;
> end;
> -----------------------------------------------------------------------
>
> Any help would be greatly appreciated!
>
> Thanks in advance,
> Udaya.
Received on Thu Jul 26 2001 - 21:19:23 CEST

Original text of this message