日期:2013-08-23  浏览次数:20413 次

判断2个时间段能否有交集的函数,开始是在我计算考勤的时候有用过,
后来发现用到的地方越来越多,  丢个砖头
9i 下通过.

两个时间段 之间能否有交集  intime---outtime
fromdate--todate
如果有交集,则前往1,否则前往0
*/
create or replace function func_IsTimeCross(intime in date, outtime in date,
fromdate date , todate date )
return number is
Result number;
begin
Result :=0;
 if (fromdate<intime) then --请假的开始时间<当天应上班的时间
                       if (todate>=outtime) then --请假的结束时间>=当天应下班时间 说明有交集
                      Result :=1;
                       end if;
 end if;
 if (fromdate>=intime) then -- 如果请假开始时间>应上班时间,只需在下班时间之前,则也说明有集
                       if (fromdate<=outtime) then
                       Result :=1;
                       end if;
 end if ;
  return(Result);
end func_IsTimeCross;