計算2個時間之間的工作日天數 是否假日表t_sys_holiday 節假日可以自己配置

以下爲ORACLE存儲過程實現

create or replace function func_getWorldNum(in_date date,--開始時間
                                             end_date date, --結束時間
                                             d_type varchar2 --日期類型G工作日,Z自然日
                                             ) return integer IS
  /************************************************************
   計算2個時間之間的工作日天數
    是否假日表t_sys_holiday
    節假日可以自己配置
  ************************************************************/
  Result      integer;

  d_num int;

begin
  --工作日
  if d_type = 'G' then
    select count(1) into d_num
  from (select to_date(t.year || '-' || t.month || '-' || t.day,
                       'yyyy-mm-dd') atime,
               t.type
          from T_SYS_HOLIDAY t) a
 where a.atime >= in_date-1 and a.atime <= decode(end_date,null,sysdate,end_date)
   and a.type = 0;

  end if;
  --自然日
  if d_type = 'Z' then
   select count(1) into d_num
  from (select to_date(t.year || '-' || t.month || '-' || t.day,
                       'yyyy-mm-dd') atime,
               t.type
          from T_SYS_HOLIDAY t) a
 where a.atime >= in_date-1 and a.atime <=decode(end_date,null,sysdate,end_date);
   --and a.type = 1
  end if;


 Result:=d_num;
  return(Result);
end func_getWorldNum;


 

 

 

---------------------------------------

t_sys_holiday表數據生成

 

select Datetime,week,isholiday from (

  select to_char(TO_DATE('2037-12-30','yyyy-MM-dd') - level, 'yyyy-MM-dd') Datetime ,to_char(TO_DATE('2037-12-30','yyyy-MM-dd') - level, 'd') week,
  decode(to_char(TO_DATE('2037-12-30','yyyy-MM-dd') - level, 'd'),
         2,0,
         3,0,
         4,0,
         5,0,
         6,0,
         7,1,
         1,1) isholiday

  from dual

connect by level <= trunc(TO_DATE('2037-12-30','yyyy-MM-dd') - TO_DATE('1990-01-01','yyyy-MM-dd'))

) --where DOW not in (7, 1);

---節假日管理自己配置修改HOLIDAY表的字段ishokiday爲1代表是

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章