Search code examples
sqloracle-databasesequences

Oralcle generate number column inline (single statement)


I am working on Oracle and I am having difficulty on generating a column of a defined range (say, 2008 to 2011). I know there is a sequences method see here.

However, I want to have it inline so that my PHP can work with it smoothly.

I also know there is a rather ugly way of doing it; for instance

select 2008 yr from dual 
union 
select 2009 yr from dual
union 
select 2010 yr from dual
union 
select 2011 yr from dual

Is there a more dynamic way?

Thanks for your kind assistance


Solution

  • Try this:

    select 2008 + level-1 yr
    from dual connect by level <  5
    

    Change constants as needed.