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!

query to get list of years

PRISMFeb 15 2013 — edited Feb 15 2013
I am trying to generate a list of years, starting with 2010 and counting up through 5 years from the current date. For example, if it is currently 2013, the list would include 2010 through 2018. 2 years from now, I want the list to go from 2010 through 2020.

I am currently using
SELECT to_char(add_months(to_date('2010','YYYY'),12 * (rownum-1)),'YYYY')
FROM dual
CONNECT BY level <= 10
to get a list with 10 entries. How can I make this dynamic enough to return a variable number of records depending on the current year?

Thanks in advance,
Tom

Edited by: PRISM on Feb 15, 2013 12:05 PM: Please disregard this message - I found what I needed in this thread:

1101400
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 15 2013
Added on Feb 15 2013
1 comment
3,752 views