仔細閱讀:
W - 周月(1-5)的第1點就開始的 月的第一天和第七結束。
WITH t AS (SELECT TO_DATE ('07-07-2016', 'dd-mm-rrrr') d FROM DUAL)
SELECT TO_CHAR (d, 'w') week,
TO_CHAR (d, 'd') day_no,
TO_CHAR (d, 'Day') Day
FROM t
WEEK DAY_NO DAY
---- ------ ----------
1 5 Donnerstag
1 row selected.
它可以使你怎麼想的那樣,獨立NLS_TERRITORY的:
WITH t AS (SELECT TO_DATE ('07-08-2016', 'dd-mm-rrrr') d FROM DUAL)
SELECT trunc(TO_CHAR (d+1, 'j')/7)-trunc(TO_CHAR (trunc(trunc(d,'mm'),'IW')+1, 'j')/7)+1 week,
TO_CHAR (d, 'd') day_no,
TO_CHAR (d, 'Day') Day
FROM t
WEEK DAY_NO DAY
---------- ------ ----------
2 1 Sonntag
1 row selected.
但是這將是有趣的,當一個月的第一天是星期六。你將在本月的第六週。
WITH t AS (SELECT TO_DATE ('30-11-2014', 'dd-mm-rrrr') d FROM DUAL)
SELECT trunc(TO_CHAR (d+1, 'j')/7)-trunc(TO_CHAR (trunc(trunc(d,'mm'),'IW')+1, 'j')/7)+1 week,
TO_CHAR (d, 'd') day_no,
TO_CHAR (d, 'Day') Day
FROM t
WEEK DAY_NO DAY
---------- ------ ----------
6 1 Sonntag
1 row selected.
:8第二週的日期不是7 –
你認爲als的第一天是星期幾?檢查你的NLS_TERRITORY設置。 –
[如何提取sql中的星期數]可能的重複(http://stackoverflow.com/questions/16530044/how-to-extract-week-number-in-sql) – Rene