ALTER SEQUENCE
Purpose
Use the ALTER SEQUENCE statement to change the increment, minimum and maximum values, cached numbers, and behavior of an existing sequence. This statement affects only future sequence numbers.
See Also:
CREATE SEQUENCE for additional information on sequences
Prerequisites
The sequence must be in your own schema, or you must have the ALTER object privilege on the sequence, or you must have the ALTER ANY SEQUENCE system privilege.
Syntax
alter_sequence::=
Semantics
The keywords and parameters in this statement serve the same purposes they serve when you create a sequence.
-
If you change the
INCREMENTBYvalue before the first invocation ofNEXTVAL, then some sequence numbers will be skipped. Therefore, if you want to retain the originalSTARTWITHvalue, you must drop the sequence and re-create it with the originalSTARTWITHvalue and the newINCREMENTBYvalue. -
Specify
RESTARTif you want to resetNEXTVALtoMINVALUEfor an ascending sequence. For a descending sequenceRESTARTresetsNEXTVALtoMAXVALUE. -
To restart the sequence at a different number, specify
RESTARTwith theSTART WITHclause to set the value at which the sequence restarts. -
If you alter the sequence by specifying the
KEEPorNOKEEPclause between runtime and failover of a request, then the original value ofNEXTVALis not retained during replay for Application Continuity for that request. -
Oracle Database performs some validations. For example, a new
MAXVALUEcannot be imposed that is less than the current sequence number.See Also:
CREATE SEQUENCE for information on creating a sequence and DROP SEQUENCE for information on dropping and re-creating a sequence
SCALE
Use SCALE to enable sequence scalability. When SCALE is specified, a numeric offset is affixed to the beginning of the sequence which removes all duplicates in generated values.
EXTEND
If you specify EXTEND with SCALE the generated sequence values are all of length (x+y), where x is the length of the scalable offset (default value is 6), and y is the maximum number of digits in the sequence (maxvalue/minvalue).
When you use SCALE it is highly recommended that you not use ORDER simultaneously on the sequence.
NOEXTEND
NOEXTEND is the default setting for the SCALE clause. With the NOEXTEND setting, the generated sequence values are at most as wide as the maximum number of digits in the sequence (maxvalue/minvalue). This setting is useful for integration with existing applications where sequences are used to populate fixed width columns.
Examples
Modifying a Sequence: Examples
This statement sets a new maximum value for the customers_seq sequence, which was created in "Creating a Sequence: Example":
ALTER SEQUENCE customers_seq MAXVALUE 1500;
This statement turns on CYCLE and CACHE for the customers_seq sequence:
ALTER SEQUENCE customers_seq CYCLE CACHE 5;
