1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
create or replace PROCEDURE BDEHISTO AS
v_Periodicite number;
v_table varchar2(50);
v_table_exception varchar2(50);
v_requete varchar2(2000);
v_verif_purge varchar2(100);
v_error_code varchar2(50);
v_error_message varchar2(100);
l_date_debut VARCHAR2(64) := To_CHAR(SYSDATE,'DD-MON-YYYY HH24:MI:SS');
v_cpt number ;
cursor C1 is
select Latable,periodicite,ladate, ladate2, jointure
from histo;
C1r C1%ROWTYPE;
BEGIN
OPEN C1;
FETCH C1 INTO C1r;
-- on parcours la table Histo
while C1%FOUND loop
-- on verifie que la table n'est pas vide
v_requete:='SELECT COUNT(*) FROM '||C1r.Latable||'@bdepkg';
EXECUTE IMMEDIATE v_requete into v_cpt ;
v_table_exception := C1r.latable;
-- si =0 on ne met rien a jour
if v_cpt>0 then
if C1r.jointure='VBL' then
v_table_exception:=v_table_exception || ' VBL';
v_requete := 'delete from '||C1r.latable||' where chronocd in ( select chronocd from vbl@bdepkg where to_date(dpre,''DD/MM/YY'') > TO_DATE(TO_CHAR(SYSDATE-'|| C1r.periodicite||',''DD/MM/YY''),''DD/MM/YY''))';
EXECUTE IMMEDIATE v_requete;
commit;
v_requete := 'insert into '||C1r.latable||' select * from '||C1r.latable||'@bdepkg where chronocd in ( select chronocd from vbl@bdepkg where to_date(dpre,''DD/MM/YY'') > TO_DATE(TO_CHAR(SYSDATE-'|| C1r.periodicite||',''DD/MM/YY''),''DD/MM/YY''))';
EXECUTE IMMEDIATE v_requete;
commit;
end if;
end if;
FETCH C1 into C1r;
end loop;
CLOSE C1;
end; |
Partager