Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Help with Triggers
FM wrote:
> Also, the 10gR2 documentation indicates that :
>
> Restrictions on AFTER Triggers AFTER triggers are subject to the
> following restrictions:
> You cannot write either the :OLD or the :NEW value.
>
> So you should change the trigger to a BEFORE trigger.
>
> FM
Where in the documentation does it say that?
SQL*Plus: Release 10.2.0.2.0 - Production on Tue Aug 22 12:15:36 2006
Copyright (c) 1982, 2005, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> CREATE TABLE person (
2 fname VARCHAR2(15),
3 lname VARCHAR2(15));
Table created.
SQL>
SQL> CREATE TABLE audit_log (
2 o_fname VARCHAR2(15), 3 o_lname VARCHAR2(15), 4 n_fname VARCHAR2(15), 5 n_lname VARCHAR2(15),
Table created.
SQL>
SQL> CREATE OR REPLACE TRIGGER referencing_clause
2 AFTER UPDATE
3 ON person
4 REFERENCING NEW AS NEW OLD AS OLD
5 FOR EACH ROW
6
7 DECLARE
8 act VARCHAR2(1);
9 BEGIN
10 INSERT INTO audit_log
11 (o_fname, o_lname, n_fname, n_lname, chng_by, chng_when)
12 VALUES
13 (:OLD.fname, :OLD.lname, :NEW.fname, :NEW.lname, USER, SYSDATE);
14 END referencing_clause;
15 /
Trigger created.
SQL> INSERT INTO person (fname, lname) VALUES ('Dan', 'Morgan');
1 row created.
SQL> UPDATE person
2 SET lname = 'Cline';
1 row updated.
SQL>
SQL> SELECT * FROM person;
FNAME LNAME
--------------- ---------------
Dan Cline
SQL> SELECT * FROM audit_log;
O_FNAME O_LNAME N_FNAME N_LNAME CHNG_BY --------------- --------------- --------------- --------------- ---------- CHNG_WHEN
-- Daniel A. Morgan University of Washington damorgan_at_x.washington.edu (replace x with u to respond) Puget Sound Oracle Users Group www.psoug.orgReceived on Tue Aug 22 2006 - 14:17:43 CDT