oracle定时任务基础

以下操作均在PL/SQL中执行

创建定时任务:

     创建定时任务的意义就是在设定好的时间对数据库进行操作。

首先我们创建一个过程(根据实际需求):

create table test(id varchar2(200),val number(4));--创建测试表

insert into test values('001',0);--插入一条测试数据

create or replace prc_test

is

--此过程操作test表,每30S 进行一次修改操作,操作内容:id为001 的数据 val值+1

update test a set a.val=a.val+1 where a.id = '001';

end;

创建job(任务)

declare   
  n_job number;
begin
DBMS_JOB.SUBMIT(job =>n_job,
    what =>'prc_test;',   --创建的存储过程名称
    next_date =>SYSDATE,
    interval =>'SYSDATE+30/(60*24*60)');
    commit;
  end;

查询job

select * from user_jobs;

查询结果中会显示现有任务的信息

获得job(字段)的值

开始执行任务

declare
        begin
          dbms_job.run(job=>5);--5 就是上述job的值
        end;

以上是基本的操作。当然还有对job的

修改

Change (job        IN binary_integer, 
                  What       IN varchar2, 
                  next_date  IN date, 
                  interval   IN varchar2)

删除

  declare
  job_n number;
   begin
   job_n:=5; --5为上述job值
        dbms_job.remove(job=>job_n);
        commit;
end

等等。

猜你喜欢

转载自vortexchoo.iteye.com/blog/2114991