Home » SQL & PL/SQL » SQL & PL/SQL » Getting Consecutive Numbers
Getting Consecutive Numbers [message #213883] Fri, 12 January 2007 11:21 Go to next message
gssunil
Messages: 7
Registered: January 2006
Location: Chicago
Junior Member

This question might have a simple solution but it has baffled me for many a months.

I would like to have the output of an SQL statment to return consecutive numbers within a range that I choose. Suppose I want a Number range 1995-2006 as below

1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006

I need a generic solution, Please give a solution not basing on any table in the database.

I have to use the result set (set of records) in my report(reports6i), So if anyone have a solution of using PL/SQL that I can use as ref cursor query, that is welcome too.


Re: Getting Consecutive Numbers [message #213884 is a reply to message #213883] Fri, 12 January 2007 11:26 Go to previous messageGo to next message
Littlefoot
Messages: 20891
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
SELECT &first + LEVEL - 1
FROM dual
CONNECT BY LEVEL < &last - &first + 2; 
Re: Getting Consecutive Numbers [message #214731 is a reply to message #213884] Wed, 17 January 2007 16:21 Go to previous message
gssunil
Messages: 7
Registered: January 2006
Location: Chicago
Junior Member

That was a good solution, thanks a ton.
Previous Topic: SQL query
Next Topic: Polling table for new data
Goto Forum:
  


Current Time: Sun Dec 04 02:41:11 CST 2016

Total time taken to generate the page: 0.12731 seconds