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: AFTER ROW Trigger Vs BEFORE ROW

Re: AFTER ROW Trigger Vs BEFORE ROW

From: <andrewst_at_onetel.com>
Date: 11 Jul 2005 07:47:52 -0700
Message-ID: <1121093271.910890.81950@g14g2000cwa.googlegroups.com>


Geoff Bruce wrote:
> It seems to me that whatever I can do in AFTER ROW trigger, I can do it in
> BEFORE ROW.
>
> Are there any functionalities that can only be achieved by AFTER ROW trigger
> but not BEFORE ROW?

Actions based on the NEW values can only be "safely" performed in an AFTER ROW trigger, because in a BEFORE ROW trigger they are not yet stable. A simple (if rather silly) example:

create trigger emp_trg1
before insert on emp
for each row
begin
  if :new.sal > 10000 then
    insert into high_paid_emps (empno) values (:new.empno);   end if;
end;
/

create trigger emp_trg2
before insert on emp
for each row
begin
  if :new.deptno = 10 then
    :new.sal := 2000;
  end if;
end;
/

Now consider the following insert:

insert into emp (empno, deptno, sal) values (1234, 10, 12000);

If emp_trg1 fires before emp_trg2 then a row will be (wrongly) created in high_paid_emps (remember, the order of trigger firing is indeterminate). Received on Mon Jul 11 2005 - 09:47:52 CDT

Original text of this message

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