oracle的工作日计算实例

    ------------------获取法定工作时间,扣除节假日--------------------------
    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 ;
 
 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值