也许这有帮助 - Oracle 查询。您将需要弄清楚如何比较您的日期并仅插入缺失的日期。开始日期是您的入境日期。其余的是另外...:
-- Annual table by date and ISO week - use WW format for non-iso week--
SELECT start_date
, TRUNC(start_date, 'iw') wk_starts
, TRUNC(start_date, 'iw') + 7 - 1/86400 wk_ends
, TO_NUMBER (TO_CHAR (start_date, 'IW')) ISO_wk#_iw
FROM
(
SELECT TRUNC(SYSDATE, 'YEAR')-1 + LEVEL AS start_date -- 11/1/2013 --
FROM dual
CONNECT BY LEVEL <=
(-- Number of Days in curr year = 365 --
SELECT TRUNC(ADD_MONTHS (SYSDATE, 12), 'Y')-TRUNC(SYSDATE, 'Y')
FROM dual
)
)
/
SQL>
START_DATE WK_STARTS WK_ENDS ISO_WK#_IW
--------------------------------------------------------------
1/1/2013 12/31/2012 1/6/2013 11:59:59 PM 1
1/2/2013 12/31/2012 1/6/2013 11:59:59 PM 1
....
1/14/2013 1/14/2013 1/20/2013 11:59:59 PM 3
1/15/2013 1/14/2013 1/20/2013 11:59:59 PM 3
....
12/29/2013 12/23/2013 12/29/2013 11:59:59 PM 52
12/30/2013 12/30/2013 1/5/2014 11:59:59 PM 1
12/31/2013 12/30/2013 1/5/2014 11:59:59 PM 1