Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: sequence in trigger
On Tue, 31 Mar 1998 14:06:42 -0800, Jim Poe <jpoe_at_fulcrumit.com> wrote:
>I need an example of using a sequence in a trigger. I tried this, but
>I get a compiler error saying that the sequence cannot be referrenced in
>this context.
>
>CREATE TRIGGER CUSTOMER_BEF_INS_KEY_ID
> BEFORE INSERT
> ON JIM.CUSTOMER
> FOR EACH ROW
> BEGIN
> :new.KEY_ID:=CUSTOMER_SEQUENCE.NextVal;
> END;
>
>Thanks
Hi Jim,
you can't access a sequence in an expression, you need to use a select statement instead. Try this:
...
FOR EACH ROW
BEGIN
SELECT CUSTOMER_SEQUENCE.NextVal
INTO :new.KEY_ID FROM dual;
-- Peter Schneider peter.schneider_at_okay.netReceived on Tue Mar 31 1998 - 00:00:00 CST
![]() |
![]() |