标签:
---------------------------陈旧的-------------------------------------
/*
--------------------- 创建job ---------------------------
variable jobno number;
begin
dbms_job.submit(jobno,
‘book_yuqi011;‘,
sysdate,
‘sysdate+1/24/60‘);
commit;
end;
/
------------------ 检查job状态 --------------------
DECLARE
jobno02 number;
BEGIN
SELECT JOB INTO JOBNO02 FROM USER_JOBS;
DBMS_OUTPUT.put_line(JOBNO02);
DBMS_JOB.remove(JOBNO02);
--SELECT JOB INTO JOBNO02 ,NEXT_DATE,NEXT_SEC,FAILURES,BROKEN FROM USER_JOBS;
END;
------------------ 删除job --------------------
BEGIN
DBMS_JOB.remove(3);
COMMIT;
END;
*/
---------------------------最新的-------------------------------------
--------------------- 创建job ---------------------------
BEGIN
SYS.DBMS_SCHEDULER.CREATE_JOB(JOB_NAME => ‘JOB_BOOK_YUQI011‘, --指定job的名称
JOB_TYPE => ‘STORED_PROCEDURE‘, --指定job操作的类型
JOB_ACTION => ‘BOOK_YUQI‘, --指定job的操作
START_DATE => TO_DATE(‘20-08-2015 17:13:20‘, ‘DD-MM-YYYY HH24:MI:SS‘), --指定job开始运行的时间
REPEAT_INTERVAL => ‘FREQ=MINUTELY;INTERVAL=1‘, --指定job运行的频率 ,常见的 daily、minutely
-- END_DATE => TO_DATE(‘21-08-2015 17:13:20‘, ‘DD-MM-YYYY HH24:MI:SS‘), --指定job结束运行的时间
JOB_CLASS => ‘DEFAULT_JOB_CLASS‘, --指定job的级别
ENABLED => TRUE, --创建job后是否启用job
AUTO_DROP => FALSE, --job是否自动删除 (默认情况下 job运行成功后,会自动删除)
COMMENTS => ‘MY NEW JOB‘); --job的注释,可有可无
END;
--------------------- 运行job ---------------------------
BEGIN
SYS.DBMS_SCHEDULER.RUN_JOB(JOB_NAME=>‘JOB_BOOK_YUQI022‘,USE_CURRENT_SESSION =>TRUE);
END;
--------------------- 检查job的运行状态 ---------------------------
SELECT JOB01.job_namE,JOB01.JOB_ACTION,JOB01.start_date,JOB01.REPEAT_INTERVAL,JOB01.AUTO_DROP,JOB01.STATE,JOB01.run_count
FROM USER_SCHEDULER_JOBS JOB01
WHERE JOB_CREATOR=‘DEV‘;
SELECT JOB_RUN.LOG_ID,JOB_RUN.LOG_DATE,JOB_RUN.OWNER,JOB_RUN.JOB_NAME,JOB_RUN.STATUS,JOB_RUN.CPU_USED
FROM USER_SCHEDULER_JOB_RUN_DETAILS JOB_RUN
WHERE JOB_NAME=‘JOB_BOOK_YUQI011‘ ORDER BY LOG_DATE DESC;
--------------------- 删除job---------------------------
BEGIN
SYS.DBMS_SCHEDULER.DROP_JOB(JOB_NAME=>‘JOB_BOOK_YUQI‘);
END;
标签:
原文地址:http://www.cnblogs.com/iyoume2008/p/4769908.html