ITPub博客

首页 > Linux操作系统 > Linux操作系统 > SQL的存储过程和任务调度

SQL的存储过程和任务调度

原创 Linux操作系统 作者:javens 时间:2008-07-14 16:19:02 0 删除 编辑
数据库: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/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 用oracle发送邮件
下一篇: RMAN异地恢复实战
请登录后发表评论 登录
全部评论

注册时间:2008-01-15

  • 博文量
    46
  • 访问量
    89196