1:每分钟执行
Interval => TRUNC(sysdate,'mi') + 1/ (24*60)
或
Interval => sysdate+1/1440
2:每天定时执行
例如:每天的凌晨1点执行
Interval => TRUNC(sysdate) + 1 +1/ (24)
3:每周定时执行
例如:每周一凌晨1点执行
Interval => TRUNC(next_day(sysdate,'星期一'))+1/24
4:每月定时执行
例如:每月1日凌晨1点执行
Interval =>TRUNC(LAST_DAY(SYSDATE))+1+1/24
5:每季度定时执行
例如每季度的第一天凌晨1点执行
Interval => TRUNC(ADD_MONTHS(SYSDATE,3),'Q') + 1/24
6:每半年定时执行
例如:每年7月1日和1月1日凌晨1点
Interval => ADD_MONTHS(trunc(sysdate,'yyyy'),6)+1/24
7:每年定时执行
例如:每年1月1日凌晨1点执行
Interval =>ADD_MONTHS(trunc(sysdate,'yyyy'),12)+1/24
variable job1 number;
begin
sys.dbms_job.submit(job => :job1 ,
what => 'declare out_state varchar2(10); begin person_market(out_state); end;',
next_date => sysdate,
interval => 'TRUNC(sysdate) + 1 +20/ (24)');
commit;
end;
variable job number;
begin
sys.dbms_job.submit(job => :job,
what => 'declare out_state varchar2(10); begin person_market(out_state); end;',
next_date => sysdate,
interval => 'sysdate+1+1/1440');
sys.dbms_job.broken(job => :job,
broken => true,
next_date => sysdate);
commit;
end;
begin
sys.dbms_job.submit(job => :job,
what => 'declare out_state varchar2(10); begin person_market(out_state); end;',
next_date => to_date('01-01-4000', 'dd-mm-yyyy'),
interval => 'TRUNC(sysdate) + 1 +20/ (24)');
sys.dbms_job.broken(job => :job,
broken => true,
next_date => to_date('01-01-4000', 'dd-mm-yyyy'));
commit;
end;
--创建一个job,这个job在创建的时候已经被运行
variable test_job number;
begin
sys.dbms_job.submit(job => :test_job, --对应的唯一id(jobId<->jobName)唯一映射
what => 'declare out_state varchar2(10); begin person_market(out_state); end;',--调用的存储过程
next_date => sysdate, --第一次执行时间
interval => 'sysdate+1/1440');--执行间隔
commit;
end;
/
--查看创建的JOB
select * from sys.user_jobs;
--执行job
begin
dbms_job.run(:job);
end;
/
--停止JOB
begin
sys.dbms_job.broken(48,true);
end;
/
begin
dbms_job.remove(:job1);
end;
-------------------------------------------------------------------------------------------------
1.创建序列
CREATE SEQUENCE hpcms_case_number
INCREMENT BY 1 -- 每次加几个
START WITH 1 -- 从1开始计数
NOMAXvalue -- 不设置最大值
NOCYCLE -- 一直累加,不循环
noCACHE ;
2.查看序列
select case_notes_number.currval from dual ;
select case_notes_number.nextval from dual ;
3.创建重置序列的存储过程
create or replace procedure reset_seq as
n_temp number(30);
s_tsql varchar2(100);
begin
execute immediate ' select hpcms_case_number.nextval from dual' into n_temp;
if n_temp <> 1 then
n_temp := - (n_temp - 1);
s_tsql := ' alter sequence hpcms_case_number increment by ' || n_temp;
execute immediate s_tsql;
execute immediate ' select hpcms_case_number.nextval from dual' into n_temp;
s_tsql := ' alter sequence hpcms_case_number increment by 1 ';
execute immediate s_tsql;
end if;
end;
4.通过job 每天凌晨12点重置序列
variable seq_job number;
begin
sys.dbms_job.submit(job => :seq_job,
what => ' begin reset_seq; end;',
next_date => sysdate,
interval => 'TRUNC(SYSDATE + 1)');
commit;
end;