Oracle SQL | Get Month Names & numbers using connect by level

Here comes a quick way to list all the months and their corresponding numbers using Oracle’s connect by level.

Select level month_number, to_char(add_months(trunc(sysdate,'YEAR'), level-1),'Month') month_name from dual connect by level < 13;

As the level starts with 0, there is no need to sort the values once again & this query could be used with Oracle forms LOVs.

2 thoughts on “Oracle SQL | Get Month Names & numbers using connect by level

Leave a Reply to windows7bugs Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.