declare v_fdate date := to_date('2013-10-4','yyyy-mm-dd'); v_ldate date := to_date('2013-10-22','yyyy-mm-dd'); v_interval_a number; v_interval_b number; v_interval_all number; begin --先算整周有几周,然后乘一周五天工作日 v_interval_a := floor((v_ldate - v_fdate)/7) * 5; --然后再算剩余的天数 v_interval_b := mod((v_ldate - v_fdate),7); --从头开始循环,共循环剩余天数次,遇到周六周日,减去一天 for i in 0..v_interval_b - 1 loop dbms_output.put_line(to_char(v_fdate + i,'day')); case to_char(v_fdate + i,'day') when '星期六' then v_interval_b := v_interval_b - 1; when '星期日' then v_interval_b := v_interval_b - 1; else null; end case; end loop; --把两部分合并起来,算出总共工作日,并输出 v_interval_all := v_interval_a + v_interval_b; dbms_output.put_line(to_char(v_fdate,'yyyy-mm-dd') || ' 到 ' || to_char(v_ldate,'yyyy-mm-dd') || ' 有 ' || v_interval_all || ' 天工作日'); end;
标签:char,ldate,天数,dd,interval,yyyy,fdate,Oracle,plsql From: https://blog.51cto.com/yuzhyn/5860705