美文网首页
oracle定时任务获取表中的数据后插入到另外指定表

oracle定时任务获取表中的数据后插入到另外指定表

作者: WJaven | 来源:发表于2018-06-26 16:13 被阅读0次

1《创建一个测试表 》

        create table t_test(dt date); 

2《创建一个存储过程 》

        create or replace procedure p_test as 

        begin 

        insert into t_test values(sysdate); 

        end; 

3《创建执行计划:每小时运行一次存储过程 》

        Declare 

        job_t Integer; 

        Begin 

        dbms_job.submit(job_t,'p_test;',Sysdate,'sysdate+1/24'); 

        end; 

4《运行执行计划

 #备注:多个job时会报错,可以带条件执行 

举个栗子:Select t.JOB into jobno From User_Jobs t <where job=10037>;  》

        Declare 

        jobno Integer; 

        Begin 

        -- 查找计划号 

        Select t.JOB into jobno From User_Jobs t ; 

        -- 运行制定的执行计划 

        dbms_job.run(jobno); 

        end; 

5《查看任务队列情况 》

        select job,next_date,next_sec,failures,broken from user_jobs; 

6《查看任务执行情况 》

        select to_char(dTime ,'yyyy/mm/dd hh24:mi:ss') from test order By dTime; 

7《停止执行计划 》

        Declare 

        jobno Integer; 

        Begin 

        -- 查找计划号 

        Select t.JOB into jobno From User_Jobs t ; 

        -- 停止计划,不再继续执行 

        --dbms_job.broken(jobno,True); 

        -- 停止计划,并在两分钟后继续执行 

        dbms_job.broken(jobno,True,Sysdate+(2/24/60)); 

        end; 

8《删除执行计划 》

        Declare 

        jobno Integer; 

        Begin 

        -- 查找计划号 

        Select t.JOB into jobno From User_Jobs t ; 

        dbms_job.remove(jobno); 

        end; 

9《修改执行计划 》

        Declare 

        jobno Integer; 

        Begin 

        -- 查找计划号 

        Select t.JOB into jobno From User_Jobs t ; 

        -- 修改为:每分钟执行一次 

        dbms_job.interval(jobno, 'sysdate+1/(24*60)'); 

        end; 

10《查看当前用户下的定时任务》

        select * from USER_JOBS;

        select job,next_date,next_sec,failures,broken from user_jobs;

也可以plsql配置:

plsql配置定时任务

《参数说明: 》

DBMS_JOB.SUBMIT(jobno =>jobID,//对应的唯一id(jobID <-> jobName)唯一映射 

procedureName=> 'your_procedure;',  //调用的存储过程名称 

next_date => sysdate,   //下次执行的时间(第一次执行的时间) 

interval => 'sysdate+1/1440');  //每次执行间隔的时间 

相关文章

网友评论

      本文标题:oracle定时任务获取表中的数据后插入到另外指定表

      本文链接:https://www.haomeiwen.com/subject/ymoseftx.html