8.8. Functions for Sequences (Generators)
8.8.1. GEN_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)
GEN_ID
Function ParametersParameter | Description |
---|---|
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.
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.1. GEN_ID
Example
|new.rec_id = gen_id(gen_recnum, 1);