标签:io ar for sp on art cti bs 工作
CREATE OR REPLACE FUNCTION FUN_GET_HOUR(STARTTIME IN VARCHAR2,ENDTIME IN VARCHAR2)RETURN NUMBER
IS
N_DAY NUMBER;--相隔天数
V_START_DAY VARCHAR2(10):=SUBSTR(STARTTIME,1,10);
V_END_DAY VARCHAR2(10):=SUBSTR(ENDTIME,1,10);
V_START_TIME VARCHAR2(10):=SUBSTR(STARTTIME,12);
V_END_TIME VARCHAR2(10):=SUBSTR(ENDTIME,12);
UP_TIME VARCHAR2(10):=‘08:30:00‘;
DOWN_TIME VARCHAR2(10):=‘17:30:00‘;
N_TIMER NUMBER;
N_MINUTE NUMBER;
N_HOURS NUMBER;
N_SECOND NUMBER;
BEGIN
SELECT TO_DATE(V_END_DAY,‘YYYY-MM-DD‘)-TO_DATE(V_START_DAY,‘YYYY-MM-DD‘) INTO N_DAY FROM DUAL;
N_DAY:=N_DAY+1;
IF N_DAY = 1 AND V_START_TIME < UP_TIME AND V_END_TIME < UP_TIME THEN
RETURN 0;
END IF;
FOR X IN 1..N_DAY LOOP
IF X=1 THEN
IF V_START_TIME > DOWN_TIME THEN
N_TIMER:=0;
ELSE
IF V_START_TIME < UP_TIME THEN
V_START_TIME:=UP_TIME;
END IF;
IF N_DAY = 1 AND DOWN_TIME > V_END_TIME THEN
DOWN_TIME:=V_END_TIME;
END IF;
N_MINUTE:=TO_NUMBER(TO_CHAR(TO_DATE(DOWN_TIME,‘HH24:MI:SS‘),‘MI‘))-TO_NUMBER(TO_CHAR(TO_DATE(V_START_TIME,‘HH24:MI:SS‘),‘MI‘));
N_HOURS:=TO_NUMBER(TO_CHAR(TO_DATE(DOWN_TIME,‘HH24:MI:SS‘),‘HH24‘))-TO_NUMBER(TO_CHAR(TO_DATE(V_START_TIME,‘HH24:MI:SS‘),‘HH24‘));
N_SECOND:=TO_NUMBER(TO_CHAR(TO_DATE(DOWN_TIME,‘HH24:MI:SS‘),‘SS‘))-TO_NUMBER(TO_CHAR(TO_DATE(V_START_TIME,‘HH24:MI:SS‘),‘SS‘));
N_TIMER:=N_MINUTE*60+N_HOURS*60*60+N_SECOND;--提交的时间
END IF;
ELSIF X=N_DAY THEN
IF V_END_TIME < UP_TIME THEN
N_TIMER:=N_TIMER+0;
ELSE
IF V_END_TIME > DOWN_TIME THEN
V_END_TIME:=DOWN_TIME;
END IF;
N_MINUTE:=TO_NUMBER(TO_CHAR(TO_DATE(V_END_TIME,‘HH24:MI:SS‘),‘MI‘))-TO_NUMBER(TO_CHAR(TO_DATE(UP_TIME,‘HH24:MI:SS‘),‘MI‘));
N_HOURS:=TO_NUMBER(TO_CHAR(TO_DATE(V_END_TIME,‘HH24:MI:SS‘),‘HH24‘))-TO_NUMBER(TO_CHAR(TO_DATE(UP_TIME,‘HH24:MI:SS‘),‘HH24‘));
N_SECOND:=TO_NUMBER(TO_CHAR(TO_DATE(V_END_TIME,‘HH24:MI:SS‘),‘SS‘))-TO_NUMBER(TO_CHAR(TO_DATE(UP_TIME,‘HH24:MI:SS‘),‘SS‘));
N_TIMER:=N_TIMER+N_MINUTE*60+N_HOURS*60*60+N_SECOND;
END IF;
ELSE
N_MINUTE:=TO_NUMBER(TO_CHAR(TO_DATE(DOWN_TIME,‘HH24:MI:SS‘),‘MI‘))-TO_NUMBER(TO_CHAR(TO_DATE(UP_TIME,‘HH24:MI:SS‘),‘MI‘));
N_HOURS:=TO_NUMBER(TO_CHAR(TO_DATE(DOWN_TIME,‘HH24:MI:SS‘),‘HH24‘))-TO_NUMBER(TO_CHAR(TO_DATE(UP_TIME,‘HH24:MI:SS‘),‘HH24‘));
N_SECOND:=TO_NUMBER(TO_CHAR(TO_DATE(DOWN_TIME,‘HH24:MI:SS‘),‘SS‘))-TO_NUMBER(TO_CHAR(TO_DATE(UP_TIME,‘HH24:MI:SS‘),‘SS‘));
N_TIMER:=N_TIMER+N_TIMER+N_MINUTE*60+N_HOURS*60*60+N_SECOND;
END IF;
END LOOP;
RETURN N_TIMER;
END FUN_GET_HOUR;
标签:io ar for sp on art cti bs 工作
原文地址:http://www.cnblogs.com/zrfmmhy/p/4056991.html