这是一个解决方案,可以在单个(尽管有点复杂)SQL 语句(这是 Oracle)中为您提供解决方案:
with all_days as (
select :start_date + (level - 1) dt
from dual
connect by :start_date + (level - 1) <= :end_date
)
select a.dt
from all_days a
where not exists (
select 1
from holidays h
where h.start_dt <= a.dt and h.end_dt >= a.dt
)
order by a.dt
例如,假设以下假期表:
NAME START_DT END_DT
-------------- ------------------------- -------------------------
Test Holiday 1 07-JUN-12 13-JUN-12
Test Holiday 2 17-JUN-12 18-JUN-12
并使用 5th June as:start_date
和 20th June as :end_date
,您将获得以下输出:
DT
-------------------------
05-JUN-12
06-JUN-12
14-JUN-12
15-JUN-12
16-JUN-12
19-JUN-12
20-JUN-12
(它提供了一个范围内的日期减去假期表中一个范围内指定的任何日期)。
希望有帮助。