DECLARE
V_CNT NUMBER := 0;
V_BEGIN_DATE DATE := DATE '2017-7-1';
V_END_DATE DATE := DATE '2017-7-7';
V_RANG VARCHAR2(2) := '09';
V_TEMP_DATE DATE;
V_TEMP_TIME VARCHAR2(2);
BEGIN
V_TEMP_DATE := V_BEGIN_DATE;
LOOP
EXIT WHEN V_TEMP_DATE > V_END_DATE;
SELECT TO_CHAR(V_TEMP_DATE, 'hh24') INTO V_TEMP_TIME FROM DUAL;
IF V_TEMP_TIME = V_RANG THEN
V_CNT := V_CNT + 1;
END IF;
V_TEMP_DATE := V_TEMP_DATE + 1 / 24;
END LOOP;
Dbms_Output.put_line(V_CNT);
END;
温馨提示:答案为网友推荐,仅供参考