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 to 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. Therefore, a statement that contains multiple references to sequence_name.NEXTVAL will return the same value for each reference of sequence_name.NEXTVAL.
Example: INSERT statement using NEXTVAL
The following example uses NEXTVAL to assign a new customer number into a customer table.
INSERT INTO pub.customer (custnum, firstname, lastname, address)
VALUES (pub.customer_sequence.NEXTVAL, 'Jane', 'Smith', '1 Maple St.');
Example: SELECT statement using CURRVAL
To find the value entered in the customer table of the preceding example, use the following statement:
SELECT pub.customer_sequence.CURRVAL from pub.customer;