select to_char(dt,'yy') ano,
to_char(dt,'mm') Mes,
to_char(dt,'iw') Semana,
max(decode( to_char(dt,'d'), 2, to_char(dt,'dd'), null )) "2a",
max(decode( to_char(dt,'d'), 3, to_char(dt,'dd'), null )) "3a",
max(decode( to_char(dt,'d'), 4, to_char(dt,'dd'), null )) "4a",
max(decode( to_char(dt,'d'), 5, to_char(dt,'dd'), null )) "5a",
max(decode( to_char(dt,'d'), 6, to_char(dt,'dd'), null )) "6a",
max(decode( to_char(dt,'d'), 7, to_char(dt,'dd'), null )) "Sa",
max(decode( to_char(dt,'d'), 1, to_char(dt,'dd'), null )) "Do"
from ( select trunc(sysdate, 'yyyy')+rownum-1 dt
from all_objects
where rownum <= 366
)
group by to_char(dt,'yy') ,
to_char(dt,'mm') ,
to_char(dt,'iw')
order by 1,2,3
/