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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| |||
| 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. |
| |||
| 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 |
| |||
| 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 |
| ||||
| 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 > |