记录如下
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;