8.8Functions for Sequences (Generators)

8.8.1GEN_ID()

Increments a sequence (generator) value and returns its new value

Result typeBIGINT — dialect 2 and 3 INTEGER — dialect 1

Syntax

  |GEN_ID (generator-name, step)

Table 8.72GEN_ID Function Parameters
ParameterDescription

generator-name

Identifier name of a generator (sequence)

step

An integer expression of the increment

If step equals 0, the function will leave the value of the generator unchanged and return its current value.

The SQL-compliant NEXT VALUE FOR syntax is preferred, except when an increment other than the configured increment of the sequence is needed.

🛑
Warning

If the value of the step parameter is less than zero, it will decrease the value of the generator. You should be cautious with such manipulations in the database, as they could compromise data integrity (meaning, subsequent insert statements could fail due to generating of duplicate id values).

8.8.1.1GEN_ID Example

  |new.rec_id = gen_id(gen_recnum, 1);

See alsoNEXT VALUE FOR, CREATE SEQUENCE (GENERATOR)