Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Avoiding recursive triggering

Re: Avoiding recursive triggering

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Wed, 08 Dec 1999 08:13:30 -0500
Message-ID: <k9ms4sk5ab7b6i5ptjhhd7nhlnn3g1lmgd@4ax.com>


A copy of this was sent to Morten Primdahl <morten_at_caput.com> (if that email address didn't require changing) On Wed, 08 Dec 1999 11:34:32 +0100, you wrote:

>
>Howdy.
>
>Is there a way I can avoid recursive triggering?
>
>CREATE OR REPLACE TRIGGER upd_trg_table
>AFTER UPDATE ON table
>FOR EACH ROW
>BEGIN
> UPDATE table SET date_changed = (SELECT ROUND(SYSDATE) FROM DUAL)
> WHERE id = :old.id;
>END;
>
>I haven't tested the above trigger, but it looks
>recursive to me. Is there some standard way to avoid
>a such recursion?

it'll get a mutating table error before it recurses.

you want to code simply:

create or replace trigger upd_trg_table BEFORE update on table for each row
begin
  :new.date_changed := round(sysdate);
end;

just change the :new variables in a BEFORE row trigger to effect the update.

>
>Thanks,
>
>Morten

--
See http://osi.oracle.com/~tkyte/ for my columns 'Digging-in to Oracle8i'... Current article is "Part I of V, Autonomous Transactions" updated June 21'st  

Thomas Kyte                   tkyte_at_us.oracle.com
Oracle Service Industries     Reston, VA   USA

Opinions are mine and do not necessarily reflect those of Oracle Corporation Received on Wed Dec 08 1999 - 07:13:30 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US