Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> Re: can I use sequence in trigger ?

Re: can I use sequence in trigger ?

From: Ronald Mohr <mail_at_ronald-mohr.de>
Date: Fri, 29 Dec 2000 00:42:01 +0100
Message-ID: <3A4BCFC9.8050900@ronald-mohr.de>

Hy Andrew
thanks a lot for the fast reply.
This way it worked.
ronald

Andrew Velichko wrote:

> Hi Ronald!
> 
> Yes, you can use sequence in triggers.
> The matter is that in PL/SQL you can't just assign sequence.nextval to
> a variable. The following should work fine:
> 

>> create or replace trigger trg_refno_ein
>> before insert on einnahmen
>> for each row
> 
> declare
> n number;
> 

>> begin
> 
> select seq_refno_ein.nextval into n from dual;
> :new.refno :=n;
 

>> --:new.refno :=seq_refno_ein.nextval;
>> end;
>> /

> 
> 
> Andrew Velichko
> Brainbench MVP for Oracle Developer 2000
> http://www.brainbench.com
> --------------------------------------------------------------
> 
> 
> "Ronald Mohr" <mail_at_ronald-mohr.de> wrote in message
> news:3A4BA6E5.6070108_at_ronald-mohr.de...
> 

>> Hy everybody
>> I tried to fire a trigger before insert on a table to add a reference
>> number to each row.
>> Therefore I used a sequence that works fine, but not within the trigger.
>> It says 'SEQ_REFNO_EIN.NEXTVAL not allowed in this context'.
>> Heres the trigger:
>>
>> create or replace trigger trg_refno_ein
>> before insert on einnahmen
>> for each row
>> begin
>> :new.refno :=seq_refno_ein.nextval;
>> end;
>> /
>>
>> Is it just a simple mistake or can't I use a sequence that way ?
>> ciao
>> Ronald
>>
Received on Thu Dec 28 2000 - 17:42:01 CST

Original text of this message

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