Oracle
 sql >> Base de Dados >  >> RDS >> Oracle

Obter primeiro dia da semana a partir do número da semana


tente isso:
select next_day(max(d), 'sun') requested_sun
  from (select to_date('01-01-2012', 'dd-mm-yyyy') + (rownum-1) d from dual connect by level <= 366)
 where to_char(d, 'ww') = 49-1;

apenas defina seu ano to_date('01-01-2012' e semana número-1 49-1 conforme aplicável.

o domingo da 49ª semana de 2008?
SQL> select next_day(max(d), 'sun') requested_sun
  2    from (select to_date('01-01-2008', 'dd-mm-yyyy') + (rownum-1) d from dual connect by level <= 366)
  3   where to_char(d, 'ww') = 49-1;

REQUESTED
---------
07-DEC-08

e 2012
SQL> select next_day(max(d), 'sun') requested_sun
  2    from (select to_date('01-01-2012', 'dd-mm-yyyy') + (rownum-1) d from dual connect by level <= 366)
  3   where to_char(d, 'ww') = 49-1;

REQUESTED
---------
02-DEC-12