What is a sequence? What can be used for? How to use it?
A sequence is an Oracle object that generates sequential numbers on demand, and guarantees that each request is satisfied with a unique value.
This is the basic way to create a sequence:
CREATE SEQUENCE Sequence_name
MINVALUE minvalue
START WITH startvalue
INCREMENT BY incrementvalue
There are two ways for reference a sequence:
CURRVAL returns the current value in the sequence.
NEXTVAL increments the current value returns the incremented value. NEXTVAL increments the sequence permanently, no matters if the current transaction is rolled back.
Before the first reference with CURRVAL, it is necessary to use NEXTVAL.
Sequences can be referenced either in SQL sentences or in PL/SQL blocks.












Leave Your Response