NEXT-VALUE function

Returns the next INT64 value of a static sequence, incremented by the positive or negative value defined in the Data Dictionary.

Syntax

NEXT-VALUE ( sequence [ , logical-dbname ] [ , tenant-id ] )
sequence
An identifier that specifies the name of a sequence defined in the Data Dictionary.
logical-dbname
An identifier that specifies the logical name of the database in which the sequence is defined. The database must be connected. If multiple databases are connected, you can omit this parameter if you specify a sequence that is unique to one of the databases.

tenant-id

An integer expression that evaluates to the tenant ID of a regular tenant, including the default tenant (0). This option applies only to a multi-tenant sequence specified by sequence and is intended for access primarily by a super-tenant user.

If you are a regular-tenant user and you specify tenant-id, the specified tenant must be the same as the tenant associated with the database connection identity for logical-dbname or the AVM raises a run-time error.

If you are a super-tenant user and you do not specify tenant-id, the function assumes the effective tenant ID (GET-EFFECTIVE-TENANT-ID function).

If the sequence specified by sequence is non-multi-tenant (a shared sequence in a multi-tenant database), and you specify tenant-id, the option is ignored.

Example

The following trigger procedure uses the NextItemNum sequence to set the ItemNum field for a new Item record:

r-critem.p

TRIGGER PROCEDURE FOR Create OF Item.

/* Automatically assign a unique item number using NextItemNum seq */
ASSIGN Item.ItemNum = NEXT-VALUE(NextItemNum).

Notes

See also

CURRENT-VALUE function, CURRENT-VALUE statement, DYNAMIC-CURRENT-VALUE function, DYNAMIC-CURRENT-VALUE statement, DYNAMIC-NEXT-VALUE function, NEXT-VALUE function