Sunday, February 4, 2024

How to get Date,Month name,Day name,the week,the number of day in oracle

 WITH

    CALENDAR_VAL

    AS

        (SELECT TO_DATE ('01' || :START_YY, 'MMRRRR')              DATE1,

                LAST_DAY (TO_DATE ('12' || :END_YY, 'MMRRRR'))     DATE2

           FROM DUAL)

    SELECT TO_CHAR (DATE1 + LEVEL - 1, 'DD-MON-RRRR')         THE_DATE,

           TO_CHAR (DATE1 + LEVEL - 1, 'fmMonth')             THE_MONTH,

           TO_CHAR (DATE1 + LEVEL - 1, 'fmDay')               DAY_NAME,

           TO_CHAR (DATE1 + LEVEL - 1, 'W')                   THE_WEEK,

           TO_CHAR (DATE1 + LEVEL - 1, 'D')                   THE_DAY,

           TO_NUMBER (TO_CHAR (DATE1 + LEVEL - 1, 'DDD'))     THE_DY

      FROM CALENDAR_VAL

CONNECT BY LEVEL <= DATE2 - DATE1 + 1

No comments:

Post a Comment