In this syntax, specify the name of the sequence that you want to remove after the DROP SEQUENCE keywords.
If you don’t specify the schema to which the sequence belongs, Oracle will remove the sequence in your own schema.
The sequence that you remove must be in your own schema or you need to have the DROP ANY SEQUENCE system privilege to remove a sequence in any schema.
The DROP SEQUENCE the statement is also useful in case you want to restart a sequence.
For example, if you have a sequence with the current value of 100 and you want to restart the sequence with a value of 50, then you can drop the sequence and re-create it with anof 50.
All the parameters have the same meaning as described in the CREATE SEQUENCE statement.
When you change the sequence’s attributes, Oracle performs some validations behind the scenes. For example, Oracle will issue an error if you change the maximum number of a sequence to a value that is less than the current sequence number.
To change the sequence at a different number, you have to drop and re-create it as follows:
In this tutorial, you’ve learned how to use the Oracle ALTER SEQUENCE statement to change the increment, minimum value, maximum value, cached numbers, and behavior of a sequence object.
Specify the name of the sequence after the CREATE SEQUENCE keywords. If you want to create a sequence in a specific schema, you can specify the schema name in along with the sequence name.
INCREMENT BY
Specify the interval between sequence numbers after the INCREMENT BY keyword.
The interval can have less than 28 digits. It also must be less than MAXVALUE - MINVALUE.
If the interval is positive, the sequence is ascending e.g., 1,2,3,…
If the interval is negative, the sequence is descending e.g., -1, -2, -3 …
The default value of interval is 1.
START WITH
Specify the first number in the sequence.
The default value of the first number is the minimum value of the sequence for an ascending sequence and maximum value of the sequence for a descending sequence.
MAXVALUE
Specify the maximum value of the sequence.
The max_value must be equal to or greater than first_number specify after the START WITH keywords.
NOMAXVALUE
Use NOMAXVALUE to denote a maximum value of 10^27 for an ascending sequence or -1 for a descending sequence. Oracle uses this option as the default.
MINVALUE
Specify the minimum value of the sequence.
The min_value must be less than or equal to the first_number and must be less than max_value.
NOMINVALUE
Use NOMINVALUE to indicate a minimum value of 1 for an ascending sequence or -10^26 for a descending sequence. This is the default.
CYCLE
Use CYCLE to allow the sequence to generate value after it reaches the limit, min value for a descending sequence and max value for an ascending sequence.
When an ascending sequence reaches its maximum value, it generates the minimum value.
On the other hand, when a descending sequence reaches its minimum value, it generates the maximum value.
NOCYCLE
Use NOCYCLE if you want the sequence to stop generating the next value when it reaches its limit. This is the default.
CACHE
Specify the number of sequence values that Oracle will preallocate and keep in the memory for faster access.
The minimum of the cache size is 2. The maximum value of the cache size is based on this formula:
In case of a system failure event, you will lose all cached sequence values that have not been used in committed SQL statements.
ORDER
Use ORDER to ensure that Oracle will generate the sequence numbers in order of request.
This option is useful if you are using Oracle Real Application Clusters. When you are using exclusive mode, then Oracle will always generate sequence numbers in order.
NOORDER
Use NOORDER if you do not want to ensure Oracle to generate sequence numbers in order of request. This option is the default.
Oracle CREATE SEQUENCE statement examples
Let’s take some example of using sequences.
1) Basic Oracle Sequence example
The following statement creates an ascending sequence called id_seq, starting from 10, incrementing by 10, minimum value 10, maximum value 100. The sequence returns 10 once it reaches 100 because of the CYCLE option.
Behind the scenes, Oracle creates a sequence that associates with the id column of the tasks table.
Because Oracle generated the sequence automatically for the id column, in your Oracle instance, the name of the sequence may be different.
Oracle uses the sys.idnseq$ to store the link between the table and the sequence.
This query returns the association of the tasks table and ISEQ$$_74366 sequence:
SELECT
a.name AS table_name,
b.name AS sequence_name
FROM
sys.idnseq$ c
JOIN obj$ a ON c.obj# = a.obj#JOIN obj$ b ON c.seqobj# = b.obj#WHERE
a.name = 'TASKS';