Accept the sysdate in the following format(YYYYMMDD)and from this date you need to go back 24 months and print all the 24 months dates in ascending order.

Showing Answers 1 - 15 of 15 Answers

OracleTooner

  • Sep 21st, 2007
 

select to_char (add_months (to_date (to_char (sysdate, 'YYYYMMDD'),
'YYYYMMDD'), -R), 'DD-Mon-YYYY') DT
from (select R
from (select rownum R
from ALL_OBJECTS
where rownum <= 24)
order by R desc)

TheSeeker

  • Oct 14th, 2010
 

SELECT   TO_CHAR (ADD_MONTHS (TO_DATE (&1, 'YYYYMMDD'), -ROWNUM),
                  'YYYYMMDD'
                 ) RESULT
    FROM user_tables
   WHERE ROWNUM < 25
ORDER BY 1;


&1 will accept the sysdate in the YYYYMMDD format or if it is always going to be sysdate, then you can do this...

SELECT   TO_CHAR (ADD_MONTHS (TO_DATE (SYSDATE, 'YYYYMMDD'), -ROWNUM),
                  'YYYYMMDD'
                 ) RESULT
    FROM user_tables
   WHERE ROWNUM < 25
ORDER BY 1;

  Was this answer useful?  Yes

Code
  1. SELECT to_char (add_months (to_date (to_char (sysdate, YYYYMMDD), YYYYMMDD), -rownum), YYYYMMDD) result  FROM ALL_OBJECTS WHERE rownum <25 ORDER BY 1;


  Was this answer useful?  Yes

Diptiman Badajena

  • Mar 29th, 2012
 

Try this one:

Code
  1. SELECT ADD_MONTHS (TRUNC(SYSDATE), (-1*(LEVEL-1))) date_calculated

  2.   FROM dual

  3. CONNECT BY LEVEL < 25

  4. ORDER BY date_calculated;

  Was this answer useful?  Yes

DURGAPRASAD

  • Jul 24th, 2012
 

Code
  1. SELECT TO_CHAR(ADD_MONTHS (SYSDATE,-LEVEL ),DD-MON-YYYY)  AS DATES    FROM DUAL  

  2. CONNECT BY LEVEL

  3. <25 ORDER BY LEVEL DESC

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions