Unix Technical Forum

request the next value for a sequence

This is a discussion on request the next value for a sequence within the DB2 forums, part of the Database Server Software category; --> Hi everybody! I wonder if there is an sql command that increases a sequence value by one and returns ...


Go Back   Unix Technical Forum > Database Server Software > DB2

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 07:06 AM
Diego
 
Posts: n/a
Default request the next value for a sequence

Hi everybody!

I wonder if there is an sql command that increases a sequence value by
one and returns such a value. I would like to manage an id inside a
program that connects to the database through jdbc. I know that there
is a command like:

select next value for public.id_seq

but this is not complete.

Thanks,

Diego
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 07:06 AM
Brian Tkatch
 
Posts: n/a
Default Re: request the next value for a sequence

Do you mean the standard use of a SEQUENCE?

db2 => CREATE SEQUENCE A
DB20000I The SQL command completed successfully.
db2 => VALUES NEXTVAL FOR A

1
-----------
1

1 record(s) selected.

db2 => VALUES NEXTVAL FOR A

1
-----------
2

1 record(s) selected.

db2 => DROP SEQUENCE A
DB20000I The SQL command completed successfully.

B.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 07:06 AM
Serge Rielau
 
Posts: n/a
Default Re: request the next value for a sequence

Diego wrote:
> Hi everybody!
>
> I wonder if there is an sql command that increases a sequence value by
> one and returns such a value. I would like to manage an id inside a
> program that connects to the database through jdbc. I know that there
> is a command like:
>
> select next value for public.id_seq
>
> but this is not complete.

Indeed:
Either
VALUES next value for public.id_seq
or
SELECT next value for public.id_seq FROM SYSIBM.SYSDUMMY1

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-27-2008, 07:07 AM
cheng.j3@gmail.com
 
Posts: n/a
Default Re: request the next value for a sequence

Is this what you need ?

E:\SQLLIB\DB2>db2 create sequence id_seq
DB20000I The SQL command completed successfully.

E:\SQLLIB\DB2>db2 -v values nextval for id_seq
values nextval for id_seq

1
-----------
1

1 record(s) selected.


E:\SQLLIB\DB2>db2 -v values nextval for id_seq
values nextval for id_seq

1
-----------
2

1 record(s) selected.


FYI . You may like to search "SEQUENCE" from DB2 UDB online
document at
http://publib.boulder.ibm.com/infoce.../v8//index.jsp

Cheng

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-27-2008, 07:08 AM
Diego
 
Posts: n/a
Default Re: request the next value for a sequence

Hi Brian, Serge and Cheng,

thanks a lot for you very useful help! That's exactly what I needed.

Diego


cheng.j3@gmail.com wrote:
> Is this what you need ?
>
> E:\SQLLIB\DB2>db2 create sequence id_seq
> DB20000I The SQL command completed successfully.
>
> E:\SQLLIB\DB2>db2 -v values nextval for id_seq
> values nextval for id_seq
>
> 1
> -----------
> 1
>
> 1 record(s) selected.
>
>
> E:\SQLLIB\DB2>db2 -v values nextval for id_seq
> values nextval for id_seq
>
> 1
> -----------
> 2
>
> 1 record(s) selected.
>
>
> FYI . You may like to search "SEQUENCE" from DB2 UDB online
> document at
> http://publib.boulder.ibm.com/infoce.../v8//index.jsp
>
> Cheng
>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:16 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com