NEXTVAL
- Last Updated: January 17, 2024
- 1 minute read
- OpenEdge
- Version 12.8
- Documentation
NEXTVAL returns a sequence's next
value. References to NEXTVAL increment the sequence
value by the defined increment and return the new value.
Use the following syntax to reference the next value of a sequence:
Syntax
|
schema.sequence. |
Parameters
- schema
-
Specifies the schema that contains the sequence. To refer to the next value of a sequence in the schema of another user, you must have
SELECTobject privilege on the sequence. - sequence
-
Specifies the name of the sequence whose next value you want.A statement referencing
NEXTVALfor a noncycling sequence returns an error after reaching the maximum value.Use
NEXTVALin the:-
SELECTlist of aSELECTstatement not contained in a subquery or view -
SELECTlist of a subquery in anINSERTstatement -
VALUESclause of anINSERTstatement -
SETclause of anUPDATEstatement
NEXTVALcannot be used in:- A query of a view
- A
SELECTstatement with aGROUP BYclause that references a sequence - A
SELECTstatement with anORDER BYclause that references a sequence - A
SELECTstatement that is combined with anotherSELECTstatement with theUNION,INTERSECT, orMINUSset operator and this restriction applies even ifUNION,INTERSECT, orMINUSoccur in a derived table clause - The
WHEREclause of aSELECTorUPDATEstatement - The
DEFAULTvalue of a column in aCREATE TABLEorALTER TABLEstatement - The condition of a
CHECKconstraint
-
Example
In
the following example, the sequence generator increments the customer sequence
and uses its value for a new customer inserted into the table pub.customer:
|