Friday, November 20, 2020

Query to get list of month and year since specific date in Oracle (Hierarchical queries - CONNECT BY Example)

 

 

 

 

 

 

 

        In this post, we have given a query which will help you to get the list of months with year information since specific date.

For example, below query will get months and year in format of JAN-2019, FEB-2019 till today.

 Query: 

SELECT TO_CHAR(ADD_MONTHS(SYSDATE,((LEVEL-1)*-1)),'MON-RRRR') mon_yyyy FROM dual CONNECT BY ADD_MONTHS(SYSDATE,((LEVEL-1)*-1)) > TO_DATE('01-01-2019','MM-DD-RRRR') ORDER BY LEVEL;

Sample Run:

0 Responses to “Query to get list of month and year since specific date in Oracle (Hierarchical queries - CONNECT BY Example)”

Post a Comment

Disclaimer

The ideas, thoughts and concepts expressed here are my own. They, in no way reflect those of my employer or any other organization/client that I am associated. The articles presented doesn't imply to any particular organization or client and are meant only for knowledge Sharing purpose. The articles can't be reproduced or copied without the Owner's knowledge or permission.