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 /