Oracle计算正常公休或工作日的PL/SQL函数

记录如下

create or replace function f_jg_sxts(date_begin in number,
                                     date_end   in number default to_char(sysdate,
                                                                          'yyyymmdd'),
                                     calctype   in number default 0)
  return number authid current_user is
  /*********************************************************************************
  计算正常公休日或正常工作日,不考虑法定节假日、地方节假日和以及附带的调整工作日
  作者:xxx
  日期:2012年6月21日
  参数:
    in
           date_begin   计算日期区间的始端
           date_end     计算日期区间的末端
           calctype     计算方式,0_计算公休日数,1_计算工作日数
    out
           无
    return
           返回指定时间区间内的而正常公休日数或正常工作日数,取决于calctype参数的输入
  修改描述:
    
  *********************************************************************************/
  date_min number;
  date_max number;
  days     number;
  exception_unknowcalctype exception;
  pragma exception_init(exception_unknowcalctype, -20000);
begin
  if date_end < date_begin then
    date_min := date_end;
    date_max := date_begin;
  else
    date_min := date_begin;
    date_max := date_end;
  end if;
  select sum(decode(to_char(to_date(date_min, 'yyyymmdd') + level - 1, 'd'),
                    1,
                    1,
                    7,
                    1,
                    0))
    into days
    from dual
  connect by level <=
             to_date(date_max, 'yyyymmdd') - to_date(date_min, 'yyyymmdd') + 1;
  if calctype = 0 then
    null;
  elsif calctype = 1 then
    days := to_date(date_max, 'yyyymmdd') - to_date(date_min, 'yyyymmdd') - days + 1;
  else
    raise_application_error(-20000, '未知的日期计算类型');
  end if;
  return(days);
end f_jg_sxts;


 调用示例

declare
  result number;
begin
  -- Call the function
  result := f_jg_sxts(20120101, to_char(sysdate, 'yyyymmdd'));
  dbms_output.put_line(result);
end;


 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值