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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
CREATEORREPLACEPROCEDURECOUNT_TABLE IS
code_S varchar2(20);
libelle_S varchar2(30);
code_M varchar2(20);
libelle_M varchar2(30);
code_C varchar2(20);
libelle_C varchar2(30);
le_sql VARCHAR2(5000);
extract_S varchar2(30);
extract_M varchar2(30);
extract_C varchar2(30);
comptage number;
BEGIN
-- on vide la table
executeimmediate'TRUNCATE TABLE TABLE_COUNT';
SELECTcocod, colib1 INTO code_S, libelle_S
FROMcode
WHEREcocod='S';
SELECT nom INTOextract_S
FROMext
WHERE exnum ='RS';
SELECTcocod, colib1 INTO code_M, libelle_M
FROMcode
WHEREcocod='W';
-- Selection de la table correspondant à l'extraction REFUSEMAIL
SELECT nom INTOextract_M
FROMext
WHERE exnum ='RE';
-- Selection des codes et libellés pour les courriers
SELECTcocod, colib1 INTO code_C, libelle_C
FROMcode
WHEREcocod='C';
SELECT nom INTOextract_C
FROMext
WHERE exnum ='NP';
-- Boucle sur les magasins
FOR c IN(SELECT decode(length(shop_id),2,'100'||shop_id,3,'10'||shop_id,1,'1000'||shop_id,4,'1'||shop_id) shop FROMcrm_shop WHERE country_id ='FR')
LOOP
BEGIN
le_sql:='select count(pers) from (select pers from idet, cart, part where cadad<>''21001231'' and camot= '' '' and fdpart.patvo like ''06%''and fdpart.pacl1=''Y'' and pers = capor and idpor = papor and idagr= '':1'' minus select expor from '||extract_S||')';
EXECUTEIMMEDIATE le_sql INTO comptage USING c.shop;
INSERTINTOTABLE_COUNT(shop_id, action_type, action_type_lab, people_number)VALUES(c.shop, code_S,libelle_S, comptage);
COMMIT;
END;
BEGIN
le_sql:='select count(pers) from (select pers from idet, cart, part where cadad<>''21001231'' and camot= '' '' and FDPART.PAAEM<>'' '' and FDPART.PACL2 IN(''Y'', ''A'', ''T'') and pers = capor and idpor = papor and idagr= '':1'' minus select expor from '||extract_M||')';
EXECUTEIMMEDIATE le_sql INTO comptage USING c.shop;
INSERTINTOTABLE_COUNT(shop_id, action_type, action_type_lab, people_number)VALUES(c.shop, code_M,libelle_M, comptage);
COMMIT;
END;
BEGIN
le_sql:='select count(pers) from (select pers from idet, cart where cadad<>''21001231'' and camot= '' '' and pers= capor and idagr= '':1'' minus select expor from '||extract_C||')';
EXECUTEIMMEDIATE le_sql INTO comptage USING c.shop;
INSERTINTOTABLE_COUNT(shop_id, action_type, action_type_lab, people_number)VALUES(c.shop, code_C,libelle_C, comptage);
COMMIT;
END;
ENDLOOP;
EXCEPTION
WHENOTHERSTHENNULL;
END;
/
|