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!

Single query to return a sequence or range of integers

13030Dec 9 2007 — edited Dec 10 2007
Here is a brain teaser for all you SQL pros...

Anyone know a way to write a single query to retrieve a range of integers? i.e. something like:

select * from some_dummy_table where n between 101 and 103

would return:

n
-----
101
102
103

the point being that I need one row for each integer in the sequence.

Of course, I could write a plsql function to return an array, and then cast that array to a table, but I could have sworn I have seen a solution like this somewhere using analytics, i.e. just SQL and not PLSQL

I could also do something with rownum and selecting from dba_objects, but I don't want this query to be dependent on how many objects are in the system or how many rows are in a given table.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 7 2008
Added on Dec 9 2007
5 comments
1,263 views