1、新增定时清理的存储过程内容如下:
CREATE OR REPLACE PROCEDURE "PROC_JOB_DEL_LOG" IS
del_date VARCHAR2(20) :=to_char(sysdate-2,'YYYY-MM-DD');--每天定时删除前一天日志信息
BEGIN
--log_ae86
insert into LOG_AE86_bak
(aaz343 ,
aab301 ,
aab299 ,
aaz341 ,
aae803 ,
aaa132 ,
aaz345 ,
aae899 ,
aae036 ,
aae011 ,
aae013 ,
aae186 ,
aae383 ,
aae140 ,
aac001 ,
aac002 ,
aac003 ,
aac004 ,
aae241
)
select aaz343 ,
aab301 ,
aab299 ,
aaz341 ,
aae803 ,
aaa132 ,
aaz345 ,
aae899 ,
aae036 ,
aae011 ,
aae013 ,
aae186 ,
aae383 ,
aae140 ,
aac001 ,
aac002 ,
aac003 ,
aac004 ,
aae241
from LOG_Ae86
where aaz343 in
(select count(aaz343)
from eventtb t
where to_char(t.starttime, 'YYYY-MM-DD') <= del_date);
--log_ae87
insert into log_ae87_bak
(aaz343 ,
aab301,
aaz341 ,
aae803 ,
aab299 ,
aac004 ,
aac003 ,
aac001 ,
aac002 ,
aaz345 ,
aae011 ,
aae036 ,
aae013 ,
aae186 ,
aae383 ,
aae899 ,
aae140 ,
aae241
)
select aaz343 ,
aab301,
aaz341 ,
aae803 ,
aab299 ,
aac004 ,
aac003 ,
aac001 ,
aac002 ,
aaz345 ,
aae011 ,
aae036 ,
aae013 ,
aae186 ,
aae383 ,
aae899 ,
aae140 ,
aae241
from LOG_Ae87
where aaz343 in
(select aaz343
from eventtb t
where to_char(t.starttime, 'YYYY-MM-DD') <= del_date);
--LOG_Ae85
insert into LOG_Ae85_bak
(AAZ343 ,
AAZ341,
AAB301,
AAB299,
AAE270,
AAE140,
AAE803,
AAC001,
AAC003,
AAC002,
AAE385,
AAE011,
AAE036,
AAE013,
AAE899,
AAE383,
AAE241
)
select
AAZ343 ,
AAZ341,
AAB301,
AAB299,
AAE270,
AAE140,
AAE803,
AAC001,
AAC003,
AAC002,
AAE385,
AAE011,
AAE036,
AAE013,
AAE899,
AAE383,
AAE241
from LOG_Ae85
where aaz343 in
(select aaz343
from eventtb t
where to_char(t.starttime, 'YYYY-MM-DD') <= del_date);
--LOG_kc90
insert into LOG_kc90_bak
(AAZ343 ,
AAE803 ,
AAZ341 ,
AAB301 ,
AAB299 ,
AAE270 ,
AAE077 ,
AAC003 ,
AAC002 ,
AAC001 ,
AAC010 ,
AAC009 ,
AAB400 ,
AAB014 ,
AAE140 ,
AAE380 ,
AAE225 ,
AAE226 ,
AAE041 ,
AAE042 ,
AAE240 ,
AAC072 ,
AAE005 ,
AAE011 ,
AAE013 ,
AAA226 ,
AAA227 ,
AAE383 ,
AAE899 ,
AAE036 ,
AAE241
)
select
AAZ343 ,
AAE803 ,
AAZ341 ,
AAB301 ,
AAB299 ,
AAE270 ,
AAE077 ,
AAC003 ,
AAC002 ,
AAC001 ,
AAC010 ,
AAC009 ,
AAB400 ,
AAB014 ,
AAE140 ,
AAE380 ,
AAE225 ,
AAE226 ,
AAE041 ,
AAE042 ,
AAE240 ,
AAC072 ,
AAE005 ,
AAE011 ,
AAE013 ,
AAA226 ,
AAA227 ,
AAE383 ,
AAE899 ,
AAE036 ,
AAE241
from LOG_kc90
where aaz343 in
(select aaz343
from eventtb t
where to_char(t.starttime, 'YYYY-MM-DD') <= del_date);
--LOG_kc91
insert into LOG_kc91_bak
(AAZ343,
AAE803 ,
AAZ341 ,
AAB301 ,
AAC003 ,
AAC002 ,
AAC004 ,
AKE100 ,
AAE173 ,
AAC028 ,
AAD019 ,
AAC072 ,
AAE011 ,
AAE005 ,
AAE036 ,
AAE013 ,
AAE383 ,
AAE899 ,
AKC111 ,
AAE140 ,
AAE241
)
select
AAZ343,
AAE803 ,
AAZ341 ,
AAB301 ,
AAC003 ,
AAC002 ,
AAC004 ,
AKE100 ,
AAE173 ,
AAC028 ,
AAD019 ,
AAC072 ,
AAE011 ,
AAE005 ,
AAE036 ,
AAE013 ,
AAE383 ,
AAE899 ,
AKC111 ,
AAE140 ,
AAE241
from LOG_kc91
where aaz343 in
(select aaz343
from eventtb t
where to_char(t.starttime, 'YYYY-MM-DD') <= del_date);
--del清理
--LOG_Ae86
delete from LOG_Ae86
where aaz343 in
(select aaz343
from eventtb t
where to_char(t.starttime, 'YYYY-MM-DD') <= del_date);
--log_ae87
delete from LOG_Ae87
where aaz343 in
(select aaz343
from eventtb t
where to_char(t.starttime, 'YYYY-MM-DD') <= del_date);
--log_ae85
delete from LOG_Ae85
where aaz343 in
(select aaz343
from eventtb t
where to_char(t.starttime, 'YYYY-MM-DD') <= del_date);
--log_kc90
delete from LOG_kc90
where aaz343 in
(select aaz343
from eventtb t
where to_char(t.starttime, 'YYYY-MM-DD') <= del_date);
--log_kc91
delete from LOG_kc91
where aaz343 in
(select aaz343
from eventtb t
where to_char(t.starttime, 'YYYY-MM-DD') <= del_date);
--空间收回
execute immediate 'alter table SITRBPZY.LOG_kc91 enable row movement';
execute immediate 'alter table SITRBPZY.LOG_kc91 shrink space';
execute immediate 'alter table SITRBPZY.LOG_kc90 enable row movement';
execute immediate 'alter table SITRBPZY.LOG_kc90 shrink space';
execute immediate 'alter table SITRBPZY.LOG_Ae85 enable row movement';
execute immediate 'alter table SITRBPZY.LOG_Ae85 shrink space';
execute immediate 'alter table SITRBPZY.LOG_ae86 enable row movement';
execute immediate 'alter table SITRBPZY.LOG_ae86 shrink space';
execute immediate 'alter table SITRBPZY.LOG_Ae87 enable row movement';
execute immediate 'alter table SITRBPZY.LOG_Ae87 shrink space';
EXCEPTION
WHEN OTHERS THEN
rollback;
COMMIT;
END PROC_JOB_DEL_LOG;
2、定时job执行清理数据库日志表信息
begin
sys.dbms_job.submit(job => :job,
what => 'PROC_JOB_DEL_LOG;',
next_date => to_date('03-11-2015 02:00:00', 'dd-mm-yyyy hh24:mi:ss'),--下次执行时间
interval => 'TRUNC(sysdate) +1+2/ (24)');--定时每天两点执行改定时任务
commit;
end;
/