DB_GET_SEQUENCE()

Generates a new sequence for a given identifier.

Syntax

DB_GET_SEQUENCE(
   id STRING )
  RETURNING result BIGINT
  1. id is the identifier of the sequence.
  2. result is the new generated sequence.

Usage

This function generates a new sequence from a register table created in the current database.

Important:
  1. Needs a database table called SEQREG.
  2. The function must be called inside a transaction block.
The table must be created as follows:
CREATE TABLE seqreg (
  sr_name VARCHAR(30) NOT NULL,
  sr_last BIGINT NOT NULL,
  PRIMARY KEY (sr_name)
)

Each time you call this function, the sequence is incremented in the database table and returned by the function.

It is mandatory to use this function inside a transaction block, in order to generate unique sequences.

MAIN
  DEFINE ns BIGINT, s INTEGER
  DATABASE mydb
  BEGIN WORK
  LET ns = DB_GET_SEQUENCE("mytable")
  INSERT INTO mytable VALUES ( ns, 'a new sequence' )
  COMMIT WORK
END MAIN