Oracle sequences - Dec 03, 2008 at 15:00 PM by Rajmeet Ghai
What are sequences? Explain with syntax.
A field in oracle can be kept as auto incremented by using sequence. it can be
used to create a number sequence.
Syntax:
CREATE SEQUENCE sequence_name
MINVALUE value
MAXVALUE value
START WITH value
INCREMENT BY value
CACHE value;
Example: employee_seq will cache up to 20 values for performance. Starts from
one.
CREATE SEQUENCE employee_seq
MINVALUE 1
MAXVALUE 999999999999999999999999999
START WITH 1
INCREMENT BY 1
CACHE 20;
List the advantages of sequences.
-
The sequence values can be cached.
-
Highly scalable.
-
Sequence ensures that no other session or other call to nextval within the same
session gets the same number from the sequence.
-
No special table needs to be created. Sequences also solve concurrency issues.
|