数据库:oralce
使用语言PL/SQL
1.存储过程
create or replace procedure com_or_pro is
o_id number := 1;
t_price number := 1;
cursor orderids is select distinct t.order_id from compete_order t where to_char(t.end_date,'yyyy-mm-dd')=to_char(sysdate-1,'yyyy-mm-dd');
begin
open orderids;
loop
fetch orderids into o_id;
select min(price) into t_price from (select order_id,price,count(*) over (partition by price) cnt from merchandise_compete_info)where order_id =o_id and cnt=1;
if t_price is not null then
update merchandise_compete_info set state='1' where order_id=o_id and price=t_price;
end if;
exit when orderids%notfound;
end loop;
close orderids;
end;
2。任务调度
declare
v_job number; //JOB名
begin
dbms_job.submit(v_job,'testL;',sysdate,TRUNC(SYSDATE+1)); //调用submit 会立即执行一次JOB
commit;
dbms_job.run(v_job);
end;
/////////////////////////////////////////////////
关于时间的设置 TRUNC(SYSDATE)+2/24 表示每天俩点
TRUNC(SYSDATE+1) 表示每天凌晨
sysdate-1 表示前一天
sysdate+5/(24*60*60) 表示每隔五秒
//////////////////////////////////////////////////
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/87010/viewspace-401202/
,如需转载,请注明出处,否则将追究法律责任。