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

Home -> Community -> Usenet -> c.d.o.server -> Re: Autoincrement

Re: Autoincrement

From: <karsten_schmidt8891_at_my-deja.com>
Date: Thu, 14 Oct 1999 14:06:22 GMT
Message-ID: <7u4o0i$kol$1@nnrp1.deja.com>


Hi,
 you need to create a trigger that automatically retrieves the next value from the sequence and fills in the field.

the syntax looks like this (pls. excuse syntax errors, im writing this without having sqlplus handy)

in SQL*Plus:

create or replace trigger auto_inc_trigger before insert on my_table
for each row
when :new.my_col is null
begin
 select my_seq.nextval into :new.my_col from dual; end;

the trigger does not override the values if somebody fills them manually, - you my get unique index violations, if those values did not come from your sequence.

Karsten

In article <7u4l5r$idt$1_at_nnrp1.deja.com>,   buurd_at_my-deja.com wrote:
> Nothing is hard about it. I just don't wanna do it manually. We are
> servleral persons that sometimes need to manually update the system as
> it looks today and the 'my_seq' is often forgotten and when
> setting 'not null' people started to inventing there own values rather
> then finding out witch sequence to use. I'll don't want human to tusch
> that column when inserting. In a simple free database mySQL there is a
> function called autoincrement. I'd like something like that but don't
> know how to do it in Oracle.
>
> Tia
>
> In article <7u4gc8$ttg$1_at_duke.telepac.pt>,
> "Luis Campos" <lcampos_at_cpcis.pt> wrote:
> > Create sequence my_seq
> > start with 1
> > increment by 1;
> >
> > insert into table (id, descr)
> > values (my_seq.NEXTVAL, 'My Description');
> >
> > What is it hard about this?
> >
> > buurd_at_my-deja.com wrote in message <7u48nb$a5r$1_at_nnrp1.deja.com>...
> > >Hi!
> > >I'm looking for a function in Oracle that would autoincrement an
> > >idcolumn so that every column gets it's own uniqe number. I'll
looked
> > >at seqences but i don't understand how to automate the process so
> that
> > >for every new row there is a new (uniqe) number.
> > >
> > >Tia
> > >
> > >--
> > >Roland Carlsson
> > >Certified Java programmer
> > >Skövde
> > >Sweden
> > >
> > >
> > >Sent via Deja.com http://www.deja.com/
> > >Before you buy.
> >
> >
>
> --
> Roland Carlsson
> Certified Java programmer
> Skövde
> Sweden
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>

Sent via Deja.com http://www.deja.com/
Before you buy. Received on Thu Oct 14 1999 - 09:06:22 CDT

Original text of this message

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