DB2 Version 9.7 for Linux, UNIX, and Windows

Viewing sequence definitions

Use the VALUES statement using the PREVIOUS VALUE option to view the reference information associated with a sequence or to view the sequence itself.

About this task

To display the current value of the sequence, issue a VALUES statement using the PREVIOUS VALUE expression:
VALUES PREVIOUS VALUE FOR id_values
 
1
-----------
          1
  
            1 record(s) selected.
You can repeatedly retrieve the current value of the sequence, and the value that the sequence returns does not change until you issue a NEXT VALUE expression. In the following example, the PREVIOUS VALUE expression returns a value of 1, until the NEXT VALUE expression in the current connection increments the value of the sequence:
VALUES PREVIOUS VALUE FOR id_values

1
-----------
          1

            1 record(s) selected.
VALUES PREVIOUS VALUE FOR id_values

1
-----------
          1

            1 record(s) selected.
VALUES NEXT VALUE FOR id_values

1
-----------
          2

            1 record(s) selected.
VALUES PREVIOUS VALUE FOR id_values

1
-----------
          2

            1 record(s) selected.

This is even true if another connection consumes sequence values at the same time.