sql >> Base de Datos >  >> RDS >> Oracle

Cómo extraer el número de semana en sql

Después de convertir su varchar2 fecha a una verdadera date tipo de datos, luego vuelva a convertir a varchar2 con la máscara deseada:

to_char(to_date('01/02/2012','MM/DD/YYYY'),'WW')

Si desea el número de la semana en un number tipo de datos, puede envolver la declaración en to_number() :

to_number(to_char(to_date('01/02/2012','MM/DD/YYYY'),'WW'))

Sin embargo, tiene varias opciones de número de semana para considerar:

WW  Week of year (1-53) where week 1 starts on the first day of the year and continues to the seventh day of the year.
W   Week of month (1-5) where week 1 starts on the first day of the month and ends on the seventh.
IW  Week of year (1-52 or 1-53) based on the ISO standard.