Quantcast
Channel: Question and Answer » oracle
Viewing all articles
Browse latest Browse all 717

Oracle custom week of the year numbering based on first Monday of the year

$
0
0

I have following sql for generating dates, I wanted to change week of the year numbering based on ‘First Monday of the Year’.

Hence numbering would be, 
01-05-15 ---> 01
01-12-15 ---> 02
01-19-15 ---> 03
...
...
...


SELECT TO_NUMBER (TO_CHAR (CurrDate, 'YYYYMMDD')) AS date_key,
   CurrDate AS alt_full_date_key,
   TO_NUMBER (TO_CHAR (CurrDate + 1, 'WW')) AS week_num_of_year,
   TO_NUMBER (TO_CHAR (CurrDate + 1, 'IW')) AS week_num_of_year_iso,
   NULL AS week_num_of_year_custom
FROM (    SELECT LEVEL n, TO_DATE ('28/12/2014', 'DD/MM/YYYY') + NUMTODSINTERVAL (LEVEL, 'day') CurrDate
          FROM DUAL
    CONNECT BY LEVEL <= 18000);

Viewing all articles
Browse latest Browse all 717

Trending Articles