oracle定时器 常用于在指定的时间或者时间间隔内对存储过程的调用
第一步写好存储过程;
第二步写job,在job中调用存储过程名,和执行时间,除了下面例子中的写法还可以通过plsql工具配置,原理完全相同,可见链接 https://www.cnblogs.com/yx007/p/6519544.html
在网上随便找的一个例子
问:我用的是ORACLE数据库,表里三个字段,id,starttime,state.
如何做在系统时间到达设置的starttime时,数据库自动修改state的值0改为1。
答:
1.create table test(id int,starttime date,state int);
2.create or replace procedure sp_update is
cursor cur is select * from test where state=0;
v_id int;
v_starttime date;
v_state int;
begin
open cur;
loop
fetch cur into v_id,v_starttime,v_state;
exit when cur%notfound;
update test set state=1 where starttime=sysdate;
commit;
end loop;
close cur;
end;
/
3.创建JOB
SQL> variable job1 number;
SQL>
SQL> begin
2 dbms_job.submit(:job1,sp_update;',sysdate,'sysdate+1/1440'); --每天1440分钟,即一分钟运行sp_update过程一次
3 end;
4 /
PL/SQL 过程已成功完成。
运行JOB
SQL> begin
2 dbms_job.run(:job1);
3 end;
4 /