一周的第一天在 Oracle 中设置为星期日而不是星期一
First Day of Week is set to Sunday instead of Monday in Oracle
我有以下查询:
SELECT forecastDate, to_char(to_date(forecastDate),'WW') AS WEEK_NUMBER
FROM ACT_FORECAST
哪个给我这个结果:
forecastDate | WEEK_NUMBER
14/07/2017 28
15/07/2017 28
16/07/2017 29
但在我所在的地区,一周从星期一开始,16/07/2017 应该有 28 个。
我的数据库的 NLS_TERRITORY 值为 'France'。
我尝试了很多东西,但没有任何效果。
有什么想法吗?
谢谢
原因是格式 WW
其中 documentation 表示:
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.
幸运的是在 ISO-8601 上一周的第一天也是星期一,所以你可以使用
SELECT forecastDate, to_char(to_date(forecastDate),'IW') AS WEEK_NUMBER
FROM ACT_FORECAST
IW
Calendar week of year (1-52 or 1-53), as defined by the ISO 8601
standard.
A calendar week starts on Monday.
The first calendar week of the year includes January 4.
The first calendar week of the year may include December 29, 30 and 31.
The last calendar week of the year may include January 1, 2, and 3.
另外,您应该将列 forecastDate
的数据类型更改为 DATE
或 TIMESTAMP
.
我有以下查询:
SELECT forecastDate, to_char(to_date(forecastDate),'WW') AS WEEK_NUMBER
FROM ACT_FORECAST
哪个给我这个结果:
forecastDate | WEEK_NUMBER
14/07/2017 28
15/07/2017 28
16/07/2017 29
但在我所在的地区,一周从星期一开始,16/07/2017 应该有 28 个。
我的数据库的 NLS_TERRITORY 值为 'France'。
我尝试了很多东西,但没有任何效果。
有什么想法吗?
谢谢
原因是格式 WW
其中 documentation 表示:
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.
幸运的是在 ISO-8601 上一周的第一天也是星期一,所以你可以使用
SELECT forecastDate, to_char(to_date(forecastDate),'IW') AS WEEK_NUMBER
FROM ACT_FORECAST
IW
Calendar week of year (1-52 or 1-53), as defined by the ISO 8601 standard.
A calendar week starts on Monday.
The first calendar week of the year includes January 4.
The first calendar week of the year may include December 29, 30 and 31.
The last calendar week of the year may include January 1, 2, and 3.
另外,您应该将列 forecastDate
的数据类型更改为 DATE
或 TIMESTAMP
.