6

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
7

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 ); 
|improve this answer|||||
4

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

did the trick

|improve this answer|||||
-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.

|improve this answer|||||
  • 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. – Lennart Feb 24 '16 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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