Home > Database > Mysql Tutorial > pl/sql获取工作时间(很实用的)

pl/sql获取工作时间(很实用的)

WBOY
Release: 2016-06-07 14:56:24
Original
1051 people have browsed it

很实用的获取工作时间 无 create or replace function FUN_GET_WORKTIME(PARAM_DATE IN DATE) return NUMBERisnum_worktime number:= 8;--工作总时长num_mi number:= 60;--60分钟num_ss number:= 60;--60秒num_work_begin number:= 8/24 + 30/(24*60);--8:30n

很实用的获取工作时间
create or replace function FUN_GET_WORKTIME(PARAM_DATE IN DATE) return NUMBER
is
num_worktime number:= 8;--工作总时长
num_mi number:= 60;--60分钟
num_ss number:= 60;--60秒
num_work_begin number:= 8/24 + 30/(24*60);--8:30
num_noon_begin number:= 11/24 + 30/(24*60);--11:30
num_noon_end number:= 12/24;--12:00
num_work_end number:= 17/24;--17:00
num_time number;--时间
num_return number;--返回值
d_init date := to_date('1988-08-08 00:00:00','YYYY-MM-DD hh24:mi:ss'); --初始日期
num_holi NUMBER;
num_holi_y NUMBER;
BEGIN
  --查询节假日表holiday
  select count(1) into num_holi from holiday h where h.holi_day < to_char(PARAM_DATE, 'YYYY-MM-DD');
  select count(1) into num_holi_y from holiday h where h.holi_day = to_char(PARAM_DATE, 'YYYY-MM-DD');
  num_return := floor(PARAM_DATE - d_init - num_holi);
  --判断当天是否为节假日
  if(num_holi_y >= 1) then
    num_return := num_return + 0;
  else
    num_time := PARAM_DATE - to_date(to_char(PARAM_DATE,'YYYY-MM-DD')||' 00:00:00','YYYY-MM-DD hh24:mi:ss');
    --时间在8:30以前至0
    if(num_time<=num_work_begin) then
      num_return := num_return + 0;
    end if;
    --时间在8:30到11:30之间
    if(num_time > num_work_begin and num_time < num_noon_begin) then
      num_return := num_return + (num_time - num_work_begin);
    end if;
    --时间在11:30到12:00之间  
    if(num_time > num_noon_begin and num_time<=num_noon_end) then
      num_return := num_return + (num_noon_begin-num_work_begin);
    end if;
    --时间在12:00到17:00之间
    if(num_time > num_noon_end and num_time<=num_work_end) then
      num_return := num_return + (num_time - num_work_begin - (num_noon_end - num_noon_begin));
    end if;  
    --时间大于17:00
    if(num_time > num_work_end ) then
      num_return := num_return + (num_work_end - num_work_begin - (num_noon_end - num_noon_begin));
    end if;  
    
  
  end if;
   num_return := num_return * num_worktime * num_mi * num_ss;
return (num_return);
end FUN_GET_WORKTIME;
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template