Search code examples
sequencederby

derby Syntax error: Encountered EOF Next Value sequence


Working with embedded database derby version 10.12.1.1. I have created a sequence successfully as below

CREATE SEQUENCE BUCKET_SEQ AS BIGINT START WITH 1000;

But when trying to get next value using

SELECT NEXT VALUE FOR BUCKET_SEQ

below error encountered:

Syntax error: Encountered "<EOF>" at line 1, column 40.

Please suggest any pointers.


Solution

  • You have to SELECT from something, and the something has to be some sort of a table.

    The simplest thing to do is to use the SQL VALUES keyword, which makes an (unnamed, temporary) table for you.

    You then give the table a name, and the table's column a name, and select the value from that:

    select t from ( values next value for bucket_seq ) s( t);
    T
    --------------------
    1000
    

    There are other syntax forms possible, but this is a simple one that you can use.