Saturday, October 9, 2010

Getting dates between period

SELECT   (TO_DATE (:start_date, 'dd-mon-yyyy') + ROWNUM - 1) "DT",
         TO_CHAR ((TO_DATE (:start_date, 'dd-mon-yyyy') + ROWNUM - 1),
                  'DD'
                 ) "DD",
         TO_CHAR ((TO_DATE (:start_date, 'dd-mon-yyyy') + ROWNUM - 1),
                  'MM'
                 ) "MM",
         TO_CHAR ((TO_DATE (:start_date, 'dd-mon-yyyy') + ROWNUM - 1),
                  'RRRR'
                 ) "RRRR",
         TO_CHAR (TO_DATE (:start_date, 'dd-mon-yyyy') + ROWNUM - 1,
                  'DY') "DD"
    FROM all_objects
   WHERE ROWNUM <=
              TO_DATE (:end_date, 'dd-mon-yyyy')
            - TO_DATE (:start_date, 'dd-mon-yyyy')
            + 1
ORDER BY TO_DATE (:start_date, 'dd-mon-yyyy') + ROWNUM - 1