10

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:  "<table_expr>".
SQLSTATE=42601
mustaccio
  • 28,207
  • 24
  • 60
  • 76
adrift
  • 375
  • 2
  • 4
  • 8

3 Answers3

11

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 ); 
Lennart - Slava Ukraini
  • 23,842
  • 3
  • 34
  • 72
6

db2 => select next value for schema_name.sequence_name from SYSIBM.SYSDUMMY1;

did the trick

adrift
  • 375
  • 2
  • 4
  • 8
-2

In this query:

select next value for schema_name.sequence_name;

next value is creating problem because we can not make the spaces while writing a query. So other thing you can do is found the max of value and increase it by 1.

Below find query for that:

select max(value)+1 for schema_name.sequence_name;

This would be helpful for you.

ypercubeᵀᴹ
  • 99,450
  • 13
  • 217
  • 306
Govind
  • 123
  • 2
  • 3
  • 13