Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Question on Sequence
Venkatesh Kumar wrote:
>
> I am planning to declare a column in my table as a
> sequence number that would increment by 1 every time I
> insert a new record in the table , automatically.
Nah. Autoincrementing is not a feature of Oracle databases.
Instead you should define a sequence:
create sequence my_sequence;
Each time you access my_sequence.nextval the counter will increment by one. Try:
SQL> select my_sequence.nextval from dual;
NEXTVAL ------- 1 SQL> select my_sequence.nextval from dual; NEXTVAL ------- 2
Next add a trigger to your table:
craete or replace trigger my_trigger before insert on my_table for each row begin select my_sequence.nextval into :new.KEY_FIELD from dual ; end;
Each time you insert a record in my_table, the field KEY_FIELD will get a unique value.
-Claus, oodac Received on Wed Dec 08 1999 - 10:42:26 CST
![]() |
![]() |