--监控JOB是否执行有异常或有停止的现象
CREATE OR REPLACE PROCEDURE P_JOB_MONITORING AS
BEGIN
FOR V IN (SELECT JOB, WHAT, FAILURES, BROKEN
FROM USER_JOBS T
WHERE T.FAILURES > 15
OR T.BROKEN = 'Y'
OR T.NEXT_DATE > TO_DATE('2070-01-01', 'yyyy-MM-dd')) LOOP
DBMS_OUTPUT.PUT_LINE(V.WHAT || '执行异常,请检查!');
DBMS_JOB.RUN(V.JOB);
DBMS_JOB.BROKEN(V.JOB, FALSE);
END LOOP;
END;
/
--1个小时执行下这个存储过程
VARIABLE JOB_NO NUMBER;
BEGIN
DBMS_JOB.SUBMIT(:JOB_NO,'P_JOB_MONITORING;',SYSDATE,'sysdate+1/24');
COMMIT;
END;
/