HiveBrain v1.2.0
Get Started
← Back to all entries
snippetModerate

How to get the next value of sequence?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
thenextvaluesequencegethow

Problem

Could somebody tell what is wrong with obvious query below:

db2 => select next value for schema_name.sequence_name;


As a result I'm getting:

SQL0104N  An unexpected token "END-OF-STATEMENT" was found following
"schema_name.sequence_name".  Expected tokens may include:  "".
SQLSTATE=42601

Solution

You need to select from something. Another option is:

db2 => values next value for schema_name.sequence_name;


As you noted you can also use SYSIBM.SYSDUMMY1 or create a virtual table:

db2 => select next value for schema_name.sequence_name from ( values 1 );

Code Snippets

db2 => values next value for schema_name.sequence_name;
db2 => select next value for schema_name.sequence_name from ( values 1 );

Context

StackExchange Database Administrators Q#126852, answer score: 10

Revisions (0)

No revisions yet.