Select
The_week,
Sunday,
Saturday,
To_char (Sunday, 'yyyymmdd') | '-' | to_char (Saturday, 'yyyymmdd') week_desc
From (select Sunday. the_week,
Decode (sign (Sunday. the_day-Saturday. the_day ),
-1,
Sunday. the_day,
Sunday. the_day-7) Sunday,
Saturday. the_day Saturday
From (select decode (to_char (wwm, 'yyyy/mm/dd'), '2014/1/01 ', '1', to_char (wwm, 'ww') + 1) the_week,
To_char (wwm, 'D') the_daynum,
Wwm the_day
From (select trunc (to_date ('1970-01-01 ', 'yyyy-mm-dd'), 'mm') + rownum-1 as wwm
From user_objects
Where rownum <366)
Where to_char (wwm, 'D') = 1 or to_char (wwm, 'yyyy/mm/dd') = '2017/01 ') Sunday,
(Select to_char (wwm, 'ww ') + 0 the_week,
To_char (wwm, 'D') the_daynum,
Wwm the_day
From (select trunc (to_date ('1970-01-01 ', 'yyyy-mm-dd'), 'mm') + rownum-1 as wwm
From user_objects
Where rownum <366)
Where to_char (wwm, 'D') = 7 or to_char (wwm, 'yyyy/mm/dd') = '2017/31') Saturday
Where Sunday. the_week = Saturday. the_week)
Where THE_WEEK =?