The CREATE SEQUENCE statement defines a database object that supplies integer values (number generator). In the following description, this object is referred to as a sequence.
<create_sequence_statement>
::= CREATE SEQUENCE [<owner>.]<sequence_name>
[INCREMENT BY <integer>] [START WITH <integer>]
[MAXVALUE <integer> | NOMAXVALUE] [MINVALUE <integer> |
NOMINVALUE]
[CYCLE | NOCYCLE]
[CACHE <unsigned_integer> | NOCACHE]
[ORDER | NOORDER]
owner, sequence_name, integer, unsigned_integer
The optional specifications after the sequence name can be specified in any order.
The current user must be a RESOURCE user or database administrator (DBA user). If an owner is specified, this must identify the current user. The current user becomes the owner of the sequence.
The integer values generated by the sequence can be used to assign key values.
Defines the difference between the next sequence value and the last value assigned. A negative value for INCREMENT BY generates a descending sequence. The value 1 is used if no value is assigned.
Defines the first sequence value. If no value is specified, the value specified for MAXVALUE or –1 is used for descending sequences and the value specified for MINVALUE or 1 for ascending sequences.
Defines the smallest value generated by the sequence. If no value is defined for MINVALUE, the smallest integer value that can be represented with 38 digits is used.
Defines the largest value generated by the sequence. If no value is defined for MAXVALUE, the largest integer value that can be represented with 38 digits is used.
CYCLE: MINVALUE is produced for ascending sequences after MAXVALUE has been assigned. MAXVALUE is produced for ascending sequences after MINVALUE has been assigned.
NOCYCLE: a request for a sequence value fails if the end of the sequence has already been reached, i.e. if MAXVALUE has been assigned for ascending sequences or MINVALUE for descending sequences.
If neither CYCLE nor NOCYCLE is specified, NOCYCLE is assumed.
CACHE: access to the sequence can be accelerated because the defined number of sequence values is held in the memory.
NOCACHE: no sequence values are defined beforehand.
If neither CACHE nor NOCACHE is specified, CACHE 20 is assumed.
Specifying ORDER or NOORDER has no effect.
Sequence values can be specified using CURRVAL and NEXTVAL (see value_spec). In this way, you can interrogate or increase the current counter value.