oracle

获取指定日期内工作日的天数

不必拘泥,可以反向思考

获取这段时期内周六日的天数,再用总天数减去周六日的天数,得到我们想要的

获取时间段内

所有日期 

select to_date('2021-11-13 02:02:00', 'yyyy-mm-dd hh24:mi:ss')+lv-1 dt
from
(
select level lv
from dual
connect by level <= trunc(sysdate -to_date('2021-11-13 02:02:00', 'yyyy-mm-dd hh24:mi:ss'), 0)
) tt

计算周六日总数

select sum(case when to_char(dt,'day')='星期六' or to_char(dt,'day')='星期日' then 1 else 0 end) as cnt
from
(
select to_date('2021-11-13 02:02:00', 'yyyy-mm-dd hh24:mi:ss')+lv-1 dt
from
(
select level lv
from dual
connect by level <= trunc(sysdate -to_date('2021-11-13 02:02:00', 'yyyy-mm-dd hh24:mi:ss'), 0)
) tt
) tm;

更多推荐