当前位置:文档之家› nextworkday函数

nextworkday函数

create or replace function nextworkDay(idate in date, n in integer,iHoliday in Number default 0)
return date as
/***********************
概要说明:
中文名称:获取上、下N个工作日
用途简述:
根据当前清算日期,获取N天前或后的工作日
语法信息:
输入参数:
idate 当前清算日期
n 往前或后几天,负数表示往前,正数表示往后
iHoliday 当天清算日是节假日是否返回上,下N个工作日,0 直接返回输入日期,1返回工作日
输出参数:
AN_O_RET_CODE 返回的代码
AC_O_RET_MSG 返回信息
******************************************/
num integer;
nextdays integer;
rdate date;
begin

nextdays := n;
rdate := idate;

if iHoliday = 0 then
--为0时判断 ,输入日期是否为节假日
select count(*) into num from QSCHILDHOLIDAY where fdate = rdate;
if num = 1 then
return rdate;
end if ;
end if;

if n > 0 then
while nextdays > 0 loop
rdate := rdate + 1;
select count(*) into num from QSCHILDHOLIDAY where fdate = rdate;
if num = 0 then
nextdays := nextdays - 1;
end if;
end loop;
end if;

if n < 0 then
nextdays := nextdays * -1;
while nextdays > 0 loop
rdate := rdate - 1;
select count(*) into num from QSCHILDHOLIDAY where fdate = rdate;
if num = 0 then
nextdays := nextdays - 1;
end if;
end loop;
end if;

return rdate;

end;

相关主题
文本预览
相关文档 最新文档