用于工作日的PLSQL函数&;从表中排除日期
我有两个约会,不包括周末和公共假日。 我设法排除了周末,但不知道如何更改我的功能以删除公共假日 有一张公共假日表用于工作日的PLSQL函数&;从表中排除日期,sql,plsql,Sql,Plsql,我有两个约会,不包括周末和公共假日。 我设法排除了周末,但不知道如何更改我的功能以删除公共假日 有一张公共假日表 Table : holidays that looks like this DT_DAY - 23/11/2017 - 02/12/2017 create or replace function BusinessDays(start_date in date, end_date in date) return number is countBusiness nu
Table : holidays that looks like this
DT_DAY
- 23/11/2017
- 02/12/2017
create or replace function BusinessDays(start_date in date, end_date in date)
return number is countBusiness number := 0; /* counter for business days */
begin
countBusiness:= (to_date(end_date,'dd-mm-yy')- to_date(start_date, 'dd-mm-yy')) +1
- (Next_Day(to_date(end_date,'dd-mm-yy'), 'Sunday')
- Next_Day(to_date(start_date,'dd-mm-yy'), 'Sunday') )/7
- (Next_Day(to_date(end_date,'dd-mm-yy'), 'Saturday')
- Next_Day(to_date(start_date,'dd-mm-yy'), 'Saturday') )/7;
return (countBusiness);
end;
排除周末的我的函数如下所示:
Table : holidays that looks like this
DT_DAY
- 23/11/2017
- 02/12/2017
create or replace function BusinessDays(start_date in date, end_date in date)
return number is countBusiness number := 0; /* counter for business days */
begin
countBusiness:= (to_date(end_date,'dd-mm-yy')- to_date(start_date, 'dd-mm-yy')) +1
- (Next_Day(to_date(end_date,'dd-mm-yy'), 'Sunday')
- Next_Day(to_date(start_date,'dd-mm-yy'), 'Sunday') )/7
- (Next_Day(to_date(end_date,'dd-mm-yy'), 'Saturday')
- Next_Day(to_date(start_date,'dd-mm-yy'), 'Saturday') )/7;
return (countBusiness);
end;
所以如果我使用
工作日(2017年11月23日、2017年11月27日)结果是3(原因包括今天11月23日、明天11月24日和周一11月27日)。
我想把我桌上的假期排除在外,这样就不算假期了。。。。就拿我刚才举的例子来说
工作日(2017年11月23日,2017年11月27日)我想要的结果是2因为2017年11月23日在我的假期表上…以下是一个改编自:
可能是Thx人的复制品!我不得不稍微适应一下,但肯定是走对了路