Using NEXTVAL

To access a sequence for the first time, you must refer to sequence.NEXTVAL before you can refer to sequence.CURRVAL. The first reference to NEXTVAL returns the initial value of the sequence. Each subsequent reference to NEXTVAL increments the value of the sequence by the defined step and returns a new incremented value of the sequence.

You can increment a given sequence only once within a single SQL statement. Even if you specify sequence.NEXTVAL more than once within a single statement, the sequence is incremented only once, so that every occurrence of sequence.NEXTVAL in the same SQL statement returns the same value.

Except for the case of multiple occurrences within the same statement, every sequence.NEXTVAL expression increments the sequence, regardless of whether you subsequently commit or roll back the current transaction.

If you specify sequence.NEXTVAL in a transaction that is ultimately rolled back, some sequence numbers might be skipped.