Help Center/ Distributed Database Middleware/ User Guide/ SQL Syntax/ Global Sequence/ Using NEXTVAL or CURRVAL to Query Global Sequence Numbers
Updated on 2024-07-30 GMT+08:00

Using NEXTVAL or CURRVAL to Query Global Sequence Numbers

  • NEXTVAL returns the next sequence number, and CURRVAL returns the current sequence number. nextval(n) returns n unique sequence numbers.
  • nextval(n) can be used only in select sequence.nextval(n) and does not support cross-schema operations.
  • currval(n) is not supported.

Procedure

  1. Connect to a DDM instance.

    For details, see Connecting to a DDM Instance.

  2. Open the required schema.
  3. Run the following command to create a global sequence:

    create sequence seq_test;

  4. Run the following command to obtain the next sequence number:

    select seq_test.nextval;

  5. Run the following command to obtain the current sequence number:

    select seq_test.currval;

  6. Run the following command to obtain sequence numbers in batches:

    select seq_test.nextval(n);

    • Cross-schema operations are not supported when sequence numbers are obtained in batches.
    • If no global sequence is used, CURRVAL returns 0.