Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> REPOST: Re: Newbie: trigger with sequences
Very close. Try:
CREATE OR REPLACE trigger EMP_TRIG
before insert on EMP
for each row
begin
select emp_ids.NEXTVAL into :new.empno from dual;
end EMP_TRIG;
/
Jim
"Nikki Woelk" <nikki_at_faludi.com> wrote in message
news:u2nihhio2mdn41_at_corp.supernews.com...
> Is there anyway to create a trigger that will automatically populate the
> primary key field with the NEXTVAL from the sequence for that table? I
> tried something like this (with sequence emp_ids already created):
>
> CREATE OR REPLACE trigger EMP_TRIG
> before insert on EMP
> for each row
> begin
> :new.empno := emp_ids.NEXTVAL;
> end EMP_TRIG;
> /
>
> but it returns with an error that "Sequence reference 'EMP_IDS.NEXTVAL'
not
> allowed in this context".
>
> Thanks.
> --
> Nikki
>
>
This message was cancelled from within Mozilla...not Received on Thu Dec 27 2001 - 20:11:18 CST