Re: Incrementation in Oracle
Date: Wed, 29 Nov 2000 17:18:14 GMT
Message-ID: <3a25388d.750812437_at_news.alt.net>
On Wed, 29 Nov 2000 14:51:34 GMT, Victor =?iso-8859-1?Q?S=E9guy?= <vseguy_at_free.fr> wrote:
>I'm new in oracle technology, i have this table :
>
>create table{
> num number,
> name varchar2(20)};
>
>I would like oracle to incremente num byitself without doing any
>counting in my application.
>Do you know if it's possible, and how too ?
>Thank's a lot
>
>Victor
>
Ceate a sequence with a trigger.
[Quoted] CREATE SEQUENCE tableSEQ INCREMENT BY 1 START WITH 1 NOMAXVALUE
NOCYCLE;
CREATE OR REPLACE TRIGGER tableANR
BEFORE INSERT ON table
FOR EACH ROW
BEGIN
SELECT tableSEQ.NEXTVAL INTO :NEW.Id From Dual;
END tableANR;
/
Of course, you may want to read the documentation on sequences so you will be more familiar with it.
Brian Received on Wed Nov 29 2000 - 18:18:14 CET