how to get Sequence PREVIOUS value

1,273 views
Skip to first unread message

Nitin Gautam

unread,
Jul 28, 2009, 8:45:01 AM7/28/09
to H2 Database
Hi,

I am using H2 with DB2 support. I have created a SEQUENCE named
ID_GEN .
"NEXT VALUE FOR ID_GEN" is working fine to get the next sequence
value but after that when I try to get Previous value of ID_GEN using
"SELECT PREVIOUS VALUE FOR ID_GEN from USR fetch first 1 rows only"
it is throwing error by saying "Column PREVIOUS not found".


please help. above code works fine in DB2


Thanks

bob mcgee

unread,
Jul 28, 2009, 12:12:19 PM7/28/09
to H2 Database
Syntax in your case:
SELECT CURRVAL(ID_GEN);

In H2, this is considered to be the current value, since it is in use,
being assigned to something.
Grammar entry for the CURRVAL function:
http://www.h2database.com/html/functions.html#currval

Cheers,
Bob McGee

Nitin Gautam

unread,
Jul 29, 2009, 5:21:12 AM7/29/09
to H2 Database
Thanks for Reply Bob.
But I don't want to modify my existing DB2 DAO code as CURRVAL is not
supported by DB2. So I rewrite the Query before execution and replaced
the instances of PREVVAL with CURRVAL syntax :-)

Thomas Mueller

unread,
Aug 4, 2009, 2:43:17 PM8/4/09
to h2-da...@googlegroups.com
Hi,

I didn't know about PREVIOUS VALUE FOR <sequence>. I will add a
feature request, but not implement it currently, sorry.

Regards,
Thomas
Reply all
Reply to author
Forward
0 new messages