Description: In Oracle, you can create an autonumber field by using sequences. A sequence is an object in Oracle that is used to generate a number sequence. This can be useful when you need to create a unique number to act as a primary key.
Once you've created a sequence object, to retrieve the next value in the sequence order you need to use NEXTVAL.
Language: PL/SQL Highlight Mode: PLSQL Last Modified: March 14th, 2009
CREATE SEQUENCE <sequence_name>
MAXVALUE <integer>/ NOMAXVALUE
MINVALUE <integer>/ NOMINVALUE
CYCLE / NOCYCLE
CACHE <#>/ NOCACHE
ORDER/ NOORDER;-- basic autonumber with sequence:INSERTINTO<table_name>(<column_name>)VALUES(<sequence_name>.NEXTVAL);-- basic autonumber with sequence demo.-- these insert statements will insert 2 new records into -- the 'test_bed' table. The user_id field would be assigned -- the next number from the seq__user_id sequence. CREATE SEQUENCE seq_user_id;SELECT seq_user_id.NEXTVALFROM dual;INSERTINTO test_bed
(user_id, class_type, room_location)VALUES(seq_user_id.NEXTVAL,'Underwater Basketweaving','RM1205');SELECT*FROM test_bed;INSERTINTO test_bed
(user_id, class_type, room_location)VALUES(seq_user_id.NEXTVAL,'Creative Anarchy','RM3111');SELECT*FROM test_bed;
SQL University.net courses meet the most demanding needs of the business world for advanced education
in a cost-effective manner. SQL University.net courses are available immediately for IT professionals
and can be taken without disruption of your workplace schedule or processes.
Compared to traditional travel-based training, SQL University.net saves time and valuable corporate
resources, allowing companies to do more with less. That's our mission, and that's what we deliver.