Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

produce a range of numbers with select from the gaps of ID column

PuraVidaOTNDec 19 2012 — edited Feb 4 2013
(1)

Suppose I have a table t which has rows like this:

A B
---------- ----------
2 4
6 7

I would like to use select to produce rows with numbers ranging between A column and B column inclusive
for each row, like this:

select ... from t ...

2
3
4
6
7

(2)

Suppose I have ID column which has gaps, I would like to get lowest <N> available numbers between the gaps.
I did research, and I can find the range of the gaps, but I cannot have the numbers listed individually, that is why
I ask question (1). But is there a direct way to get the list instead of going through ranges and the list.

For example, I have ID column which has

2
5
6
7
9
2000000

I would like to get a select query that produces

select ...

3
4
8
10
11

I have a way to get a list from 2 to 2000000 and then minus what we have to get all the
gap numbers, but that is not efficient and could runs out of memory.

PS: Before I post to this group, I did research already on "connect by", with recursive queries.
This post has been answered by jeneesh on Dec 19 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 4 2013
Added on Dec 19 2012
5 comments
2,852 views