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日参数:indate_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);
beginif date_end < date_begin thendate_min := date_end;date_max := date_begin;elsedate_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 daysfrom dualconnect by level <=to_date(date_max, 'yyyymmdd') - to_date(date_min, 'yyyymmdd') + 1;if calctype = 0 thennull;elsif calctype = 1 thendays := to_date(date_max, 'yyyymmdd') - to_date(date_min, 'yyyymmdd') - days + 1;elseraise_application_error(-20000, '未知的日期计算类型');end if;return(days);
end f_jg_sxts;
调用示例
declareresult number;
begin-- Call the functionresult := f_jg_sxts(20120101, to_char(sysdate, 'yyyymmdd'));dbms_output.put_line(result);
end;
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
