Here are some facts you may want to consider if you use or are planning to use sequences in Oracle.
You cannot use CURRVAL and NEXTVAL in the following constructs:
DELETE, SELECT, or UPDATE statementSELECT statement with the DISTINCT operatorSELECT statement with a GROUP BY clause or ORDER BY clauseSELECT statement that is combined with another SELECT statement with the UNION, INTERSECT, or MINUS set operatorWHERE clause of a SELECT statementDEFAULT value of a column in a CREATE TABLE or ALTER TABLE statementCHECK constraintAlso, within a single SQL statement that uses CURRVAL or NEXTVAL, all referenced LONG columns, updated tables, and locked tables must be located on the same database.
When you create a sequence, you can define its initial value and the increment between its values. The first reference to NEXTVAL returns the sequence’s initial value. Subsequent references to NEXTVAL increment the sequence value by the defined increment and return the new value. Any reference to CURRVAL always returns the sequence’s current value, which is the value returned by the last reference to NEXTVAL. Note that before you use CURRVAL for a sequence in your session, you must first initialize the sequence with NEXTVAL.
Related articles: