Home > Database > Mysql Tutorial > 学习Oracle环境中job创建

学习Oracle环境中job创建

WBOY
Release: 2016-06-07 17:20:15
Original
984 people have browsed it

Oracle中job的创建: create table date_log(create_date date constraint create_date_pk primary key); create or replace pro

Oracle中job的创建:

create table date_log(create_date date constraint create_date_pk primary key);

create or replace procedure create_date_log_row
 is
 begin
   insert into date_log(create_date)values(sysdate);
   end;
   /
  
定期调用create_date_log_row  存储过程相date_log 表中插入数据

Job_queue_processes=2  :执行job时候引起的进程数 (最小值是0,最大值是36) 0表示不运行 job

job_queue_interval=30  :范围在1~3600之间,单位是秒,定期唤醒进程,判断有没有要执行的job,这里时间是30秒

alter system set Job_queue_processes=0;

alter system set Job_queue_processes=5;

dbms_job.submit(:jobno,'create_date_log_row',trunc(sysdate)+1/24,'trunc(sysdate)+1/24+1')

jobno:job编号

create_date_log_row :要执行的存储过程名

trunc(sysdate)+1/24 :下次执行的时间

'trunc(sysdate)+1/24+1' :每次间隔时间

job:dbms_job.remove(jobno); 移去job号

job:dbms_job.what(jobno,what);修改job号

dbms_job.next_date(job,next_date) :修改下次执行的时间

dbms_job.interval(job,interval)   :修改间隔时间
 
job:dbms_job.broken(job,true)     :停止job

job:dbms_job.broken(job,false,next_date)   next_date:下次执行时间,,如果不填则马上启动job

job:dbms_job.run(jobno);

第一步:创建任务

SQL>VAR job1 number;  --存储job号码

SQL>begin
    dbms_job.submit(:job1,'create_date_log_row;',sysdate,'sysdate+1/1440');
    commit;
    end;

SQL>PRINT job1;

select * from date_log;

--查看job参数的值

select last_date,last_sec,next_date,next_sec,interval,broken from user_jobs;

--停止正在运行的job

exec dbms_job.broken(46,true);
commit;
 
select broken from user_jobs where job=46;

--启动job

exec dbms_job.broken(46,false);
commit;

--
select next_date,next_sec from user_jobs;

修改下次执行时间:

exec dbms_job.next_date(5,sysdate+2/(24*60));
commit;

-- 修改执行的频率

exec dbms_job.interval(5,sysdate+3/(24*60));
commit;

--移去job
job:dbms_job.remove(46);


--执行时间设置:

每天午夜12点 'trunc(sysdate+1)'
每天早上8点30分 'trunc(sysdate+1)+(1*60+30)/(24*60)'
每星期二中午12点 'next_day(trunc(sysdate),"tuesday")+ 12/24'
每个月第一天的晚上11点 'trunc(last_day(sysdate)+1)'
每个季度最后一天的晚上11点 'trunc(add_months(sysdate+2/24,3),'Q')-1/24'
每星期六和日早上6点10分 'trunc(least(next_day(sysdate"SATURDAY"),NEXT_DAY(SYSDATE,"SUNDAY")))+(6*60+10)/(24*60)'

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template