------------------获取法定工作时间,扣除节假日--------------------------
create or replace function getTheWorkDay(begindate in varchar2 , maxlongtime in Integer )
return date
is
betday date; -- 返回获得的日期
js Integer : = 0 ; -- 计数
scts INTEGER ; -- 某天距2001-12-30(已知的星期天)所差的天数
tempyear varchar ( 12 ); -- 暂存年
tempnextyear varchar ( 12 ); -- 暂存下一年
begin
betday: = to_date(begindate, ' YYYYMMDD ' );
tempyear: = extract( year from betday);
-- tempdate:= next_day(to_date(concat('2007','1201'),'YYYYMMDD'),1);--当年最后一天
tempnextyear: = to_char(to_number(tempyear) + 1 );
LOOP
betday: = betday + 1 ;
scts : = betday - to_date( ' 20011230 ' , ' yyyymmdd ' ); -- 计算星期六、星期天
IF MOD(MOD(scts, 7 ) + 7 , 7 ) NOT IN ( 0 , 6 ) THEN
-- 扣除五一
IF betday not between to_date(concat(tempyear, ' 0501 ' ), ' yyyymmdd ' ) and to_date(concat(tempyear, ' 0507 ' ), ' yyyymmdd ' ) then
-- 扣除十一
IF betday not between to_date(concat(tempyear, ' 1001 ' ), ' yyyymmdd ' ) and to_date(concat(tempyear, ' 1007 ' ), ' yyyymmdd ' ) then
-- 扣除元旦
IF betday not between to_date(concat(tempnextyear, ' 0101 ' ), ' yyyymmdd ' ) and to_date(concat(tempnextyear, ' 0103 ' ), ' yyyymmdd ' ) then
js: = js + 1 ;
END IF ;
END IF ;
END IF ;
END IF ;
EXIT WHEN js >= maxlongtime;
END LOOP;
return (betday);
end ;
create or replace function getTheWorkDay(begindate in varchar2 , maxlongtime in Integer )
return date
is
betday date; -- 返回获得的日期
js Integer : = 0 ; -- 计数
scts INTEGER ; -- 某天距2001-12-30(已知的星期天)所差的天数
tempyear varchar ( 12 ); -- 暂存年
tempnextyear varchar ( 12 ); -- 暂存下一年
begin
betday: = to_date(begindate, ' YYYYMMDD ' );
tempyear: = extract( year from betday);
-- tempdate:= next_day(to_date(concat('2007','1201'),'YYYYMMDD'),1);--当年最后一天
tempnextyear: = to_char(to_number(tempyear) + 1 );
LOOP
betday: = betday + 1 ;
scts : = betday - to_date( ' 20011230 ' , ' yyyymmdd ' ); -- 计算星期六、星期天
IF MOD(MOD(scts, 7 ) + 7 , 7 ) NOT IN ( 0 , 6 ) THEN
-- 扣除五一
IF betday not between to_date(concat(tempyear, ' 0501 ' ), ' yyyymmdd ' ) and to_date(concat(tempyear, ' 0507 ' ), ' yyyymmdd ' ) then
-- 扣除十一
IF betday not between to_date(concat(tempyear, ' 1001 ' ), ' yyyymmdd ' ) and to_date(concat(tempyear, ' 1007 ' ), ' yyyymmdd ' ) then
-- 扣除元旦
IF betday not between to_date(concat(tempnextyear, ' 0101 ' ), ' yyyymmdd ' ) and to_date(concat(tempnextyear, ' 0103 ' ), ' yyyymmdd ' ) then
js: = js + 1 ;
END IF ;
END IF ;
END IF ;
END IF ;
EXIT WHEN js >= maxlongtime;
END LOOP;
return (betday);
end ;