Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Trigger to set ID field using sequence
"Mike DiChiappari" <mike_at_mysticsoft.com> writes:
>
> CREATE TRIGGER MYDB.visitors_auto_id
> BEFORE INSERT ON MYDB.visitors
> BEGIN
> :new.ID := MYDB.VISITORSEQ.NEXTVAL;
> END;
>
> When I try to run this PL/SQL, I get the error:
>
> CREATE TRIGGER MYDB.visitors_auto_id
> *
> ORA-04082: NEW or OLD references not allowed in table level triggers
>
I think you need to add the "FOR EACH ROW" directive in your trigger
definition so that it is defined as a row trigger rather than a table
trigger - the difference is that a row trigger fires for each row
affected while a table trigger fires for each "operation" on the table
(which may affect 1 or more rows). e.g.
CREATE TRIGGER .....
BEFORE INSERT ON .....
FOR EACH ROW
BEGIN
.....
Tim Received on Mon Jun 17 2002 - 18:12:18 CDT