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

3 Answers 3

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 ); 
0
6

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

did the trick

-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.

1
  • you can't select from nothing in db2. You need to use either values next value for schema_name.sequence_name or select next value for schema_name.sequence_name from .... In addition you cant apply max to value the way you do, next value for schema_name.sequence_name is an expression that returns the next value from the sequence. Commented Feb 24, 2016 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.