CreateTime--2017年9月7日17:14:56
Author:Marydon
ORACLE判断两个日期间隔几个工作日
方法:使用存储过程
/**
* 判断两个日期间隔几个工作日
*/
CREATE OR REPLACE FUNCTION "FUN_BETWEENDAYS"(start_dt date, end_dt date)
RETURN INT IS
t_days INT;
BEGIN
SELECT (TRUNC(end_dt - start_dt) - ((CASE
WHEN (8 - to_number(to_char(start_dt, 'D'))) >
TRUNC(end_dt - start_dt) + 1 THEN
0
ELSE
trunc((TRUNC(end_dt - start_dt) -
(8 - to_number(to_char(start_dt, 'D')))) / 7) + 1
END) + (CASE
WHEN MOD(8 - to_char(start_dt, 'D'), 7) >
TRUNC(end_dt - start_dt) - 1 THEN
0
ELSE
TRUNC((TRUNC(end_dt - start_dt) -
(MOD(8 - to_char(start_dt, 'D'), 7) + 1)) / 7) + 1
END)))
INTO t_days
FROM dual;
RETURN t_days;
END FUN_BETWEENDAYS;