Oracle - Create an autonumber field
Written on January 6, 2008 – 4:41 am | by André Gomes
If you want to create an autoincrements field in a table, using Oracle, you may do this by using sequences.
What are sequences?
Well, sequence is a command that gives to you the power to do this.
Nothing better than an example:
create table user ( id number(10), name varchar2(32), primary key(id) );
If you want the id field increase automatically, you use the sequence:
create sequence user_seq start with 1 increment by 1 nomaxvalue;
Naturally, as you can see, when new records are entry on table, the id field will be increasing.
insert into user values(user_seq.nextval, 'andre'); select * from user
… Experiment yourself now
Just for curiosity, the sintaxe of sequence is:
CREATE SEQUENCE sequence_name
MINVALUE value
MAXVALUE value
START WITH value
INCREMENT BY value
CACHE value;
Veja também:
- Insert an autonumber field on SQL Server
- Insert a uniqueidentifier field on SQL Server
- Árvores Binárias em XML
- Ubuntu 7.10
- AlertPay - Transferência para conta portuguesa
Tags: oracle, programação, sql

2 Responses to “Oracle - Create an autonumber field”
By nunojob on Jan 6, 2008 | Reply
Good article
Congrats! =)