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: Trigger to set ID field using sequence

Re: Trigger to set ID field using sequence

From: Tim Cross <tcross_at_pobox.une.edu.au>
Date: 18 Jun 2002 09:12:18 +1000
Message-ID: <871yb51ovh.fsf@blind-bat.une.edu.au>


"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

Original text of this message

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