oracle起定时任务,每隔1秒执行一次

来源:互联网 发布:subnautica mac 编辑:程序博客网 时间:2024/05/21 09:37
建一个测试表和一个存储过程:
[sql] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. create table a(a date);  
  2.   
  3. create or replace procedure test as   
  4.     begin   
  5.     insert into a values(sysdate);   
  6.    end;   


定时任务样板:

[sql] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. declare  
  2. job1 number;   
  3. begin  
  4.  dbms_job.submit(job1,  
  5.      what => 'test;',  
  6.      next_date => sysdate,  
  7.      interval => 'sysdate+1/(24*60*60)'); -- 每隔1s处理一次用户表  
  8.    commit;  
  9. end;  

查询定时任务:
[sql] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. select job,broken,what,interval,t.* from user_jobs t;     


删除定时任务:

[sql] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. begin  
  2.        dbms_job.remove('24');  
  3.        commit;  
  4. end;  



  1. Interval => TRUNC(sysdate+1)  --每天凌晨0点执行  
  2. Interval => TRUNC(sysdate+1)+1/24  --每天凌晨1点执行 


启动定时任务:

[sql] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. begin    
  2.       dbms_job.run(24);  -- 24jod id  
  3. --      commit;  
  4. end;   











create or replace procedure backUpDayMessage as
begin
  insert into t_call_message_2017
    select *
      from t_Call_Message t
     where to_char(t.visit_time, 'YYYYMMDD') =
           to_char(TRUNC(sysdate - 1), 'YYYYMMDD');
end;

 
  declare
    backUpDayMessageJob number;
  begin
    dbms_job.submit(backUpDayMessageJob,
                    what => 'backUpDayMessage;',
                    next_date => TRUNC(sysdate) + 1 ,
                    interval => 'TRUNC(SYSDATE) +1+ 1 / 24');  
    commit;
  end;





0 0
原创粉丝点击