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!

How do get last 12 months using connect by level

LotsVivSep 5 2020 — edited Sep 9 2020

Hi: I am on Oracle 12c and I have this query that I like to modify.   Instead of going forward 12 months, I would like to modify it to go backward 12 months from a given date.

Thank you.

       SELECT  LEVEL  AS num, TO_CHAR ( ADD_MONTHS (to_date('9/5/2020','mm/dd/yyyy'), LEVEL - 1)  ,'MON_YY')  AS str, sysdate

       FROM  dual CONNECT BY  LEVEL <=  12

This post has been answered by LotsViv on Sep 5 2020
Jump to Answer
Comments
Post Details
Added on Sep 5 2020
6 comments
7,262 views