1:首先看创建一个函数
给定一个日期,判断是否是休息日.
1createorreplacefunction test(date_inin date) 2returnint 3is 4 numint; 5 workflagvarchar2(1); 6begin 7selectcount(*)into numfrom Sys_Holiday 8where to_char(TODAY,'yyyy-MM-dd')=to_char(date_in,'yyyy-MM-dd'); 910if (num>0)then11select WORKFLAGinto workflagfrom Sys_Holiday 12where to_char(TODAY,'yyyy-MM-dd')=to_char(date_in,'yyyy-MM-dd'); 13if (workflag='W')then14return0; 15else16return1; 17endif; 18else19select to_char(date_in,'D')into numfrom dual; 20if (num=7or num=1)then21return1; 22else23return0; 24endif; 25endif; 26end;
2:另外一个函数调用这个函数,一个日期增加或减少多少天对应的日期(工作日)
1CREATEORREPLACEFUNCTION getWorkDayADD(datetimein date,workdayinint)return date 2is 3 dayflagint;--初始值,写循环 4 sumflagint;--判断值 5 datetime1 date; 6 workday1int; 7 sysdateadd date; 8 daynumint; 9 sysdatelast date;--返回值10begin11 datetime1 :=datetime; 12 workday1 := workday; 13 dayflag :=0; 14 sumflag :=1; 15if(workday1>0)--加减多少来决定16then17while (sumflag=workday1) loop 18 dayflag := da