If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > how to do bulk generation of sequence

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-03-04, 03:06
vijpan vijpan is offline
Registered User
 
Join Date: Jan 2004
Posts: 7
how to do bulk generation of sequence

is it possible to generate bulk seuence numbers from a single sql query. Lets say there is a sequence name "test_seq". The curent value on that sequence is lets say 10, if i want to get the next 20 sequence in a sql query, how i will do that, i want to get those 20 values in the resultset through java.

Thanks
Reply With Quote
  #2 (permalink)  
Old 01-07-04, 06:15
jsander jsander is offline
Registered User
 
Join Date: Apr 2003
Posts: 191
Re: how to do bulk generation of sequence

Hi,

documentation does not suggest there is a way to retrieve a couple of different NEXTVALs for YOURSEQENCE in a single query. But there are other options:

a) create a sequence with an INCREMENT BY 20 clause, and let the application do the filling of the gaps or
b) retrieve 20 NEXTVALs through the application or
c) create a table function making use of procedure language, retrieve 20 NEXTVALs in a loop

Would be interesting to know what you are going to settle with.

Johann
Quote:
Originally posted by vijpan
is it possible to generate bulk seuence numbers from a single sql query. Lets say there is a sequence name "test_seq". The curent value on that sequence is lets say 10, if i want to get the next 20 sequence in a sql query, how i will do that, i want to get those 20 values in the resultset through java.

Thanks
Reply With Quote
  #3 (permalink)  
Old 01-07-04, 06:47
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Re: how to do bulk generation of sequence

d) Use a recursive SQL to retrieve 20 values

Cheers
Sathyaram

Quote:
Originally posted by jsander
Hi,

documentation does not suggest there is a way to retrieve a couple of different NEXTVALs for YOURSEQENCE in a single query. But there are other options:

a) create a sequence with an INCREMENT BY 20 clause, and let the application do the filling of the gaps or
b) retrieve 20 NEXTVALs through the application or
c) create a table function making use of procedure language, retrieve 20 NEXTVALs in a loop

Would be interesting to know what you are going to settle with.

Johann
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #4 (permalink)  
Old 01-07-04, 06:54
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
Here's a hack...

with nextvals(counter) as
(
values (1)
union all
select counter + 1
from nextvals
where counter < 20
)
select nextval for your_sequence
from nextvals
;

Damian
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On