CREATE SEQUENCE Statement (create_sequence_statement)
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.
Syntax
<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]
Explanation
The sequence names can be specified in any order.
The current user must have
RESOURCE or DBA status. If an owner is specified, it 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.
INCREMENT BY
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.
START WITH
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.
MINVALUE
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.
MAXVALUE
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/NOCYCLE
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/NOCACHE
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.
ORDER/NOORDER
Specifying ORDER or NOORDER has no effect.
Sequence values can be specified using CURRVAL and NEXTVAL (see