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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
--tableau de résultats annoté
type res is record (ID number,
Montant number,
pres_donnees number,
Ordre number(5,0));
type tableau_res is table of res not null index by varchar(20);
resultat tableau_res;
type Tab_Offre is table of number index by binary_integer;
Offre Tab_Offre;
type Tab_demande is table of number index by binary_integer;
demande Tab_demande;
cursor mont_1_CRI is select DC1, DC2, DC3, DC4, DC5, DC6, DC7, DC8, DC9, SUM(Montant) as montant from Tbl_donnees
where (DC1 <> 0 or DC2 <> 0 or DC3 <> 0 or DC4 <> 0 or DC5 <> 0 or DC6 <> 0 or DC7 <> 0 or DC8 <> 0 or DC9 <> 0)
and not (DC1 is not null and DC2 is not null and DC3 is not null and DC4 is not null and DC5 is not null
and DC6 is not null and DC7 is not null and DC8 is not null and DC9 is not null) group by DC1, DC2, DC3, DC4, DC5, DC6, DC7, DC8, DC9;
montant_1_CRI mont_1_CRI%rowtype;
for montant_1_CRI in mont_1_CRI loop
demande(1) := montant_1_CRI.DC1;
if demande(1) is not null then
cpt_zero := cpt_zero + 1;
critere1 := ' DC1 = '|| demande(1) ;
jointure := 'C1 = DC1';
else
critere1 := critere1 || ' DC1 is null';
cpt_zeroj := cpt_zeroj + 1;
end if;
demande(2) :=montant_1_CRI.DC2;
if demande(2) is not null then
cpt_zero := cpt_zero + 1;
critere1 := critere1 || ' and DC2 = '|| demande(2) ;
if cpt_zero = 1 then
jointure := 'C2 = DC2';
else
jointure := jointure || ' and C2 = DC2';
end if;
else
critere1 := critere1 || ' and DC2 is null';
end if;
demande(3) :=montant_1_CRI.DC3;
if demande(3) is not null then
cpt_zero := cpt_zero + 1;
critere1 := critere1 || ' and DC3 = '|| demande(3) ;
if cpt_zero = 1 then
jointure := 'C3 = DC3';
else
jointure := jointure || ' and C3 = DC3';
end if;
else
critere1 := critere1 || ' and DC3 is null';
end if;
demande(4) :=montant_1_CRI.DC4;
if demande(4) is not null then
cpt_zero := cpt_zero + 1;
critere1 := critere1 || ' and DC4 = '|| demande(4) ;
if cpt_zero = 1 then
jointure := 'C4 = DC4';
else
jointure := jointure || ' and C4 = DC4';
end if;
else
critere1 := critere1 || ' and DC4 is null';
end if;
demande(5) :=montant_1_CRI.DC5;
if demande(5) is not null then
cpt_zero := cpt_zero + 1;
critere1 := critere1 || ' and DC5 = '|| demande(5) ;
if cpt_zero = 1 then
jointure := 'C5 = DC5';
else
jointure := jointure || ' and C5 = DC5';
end if;
else
critere1 := critere1 || ' and DC5 is null';
end if;
demande(6) :=montant_1_CRI.DC6;
if demande(6) is not null then
cpt_zero := cpt_zero + 1;
critere1 := critere1 || ' and DC6 = '|| demande(6) ;
if cpt_zero = 1 then
jointure := 'C6 = DC6';
else
jointure := jointure || ' and C6 = DC6';
end if;
else
critere1 := critere1 || ' and DC6 is null';
end if;
demande(7) :=montant_1_CRI.DC7;
if demande(7) is not null then
cpt_zero := cpt_zero + 1;
critere1 := critere1 || ' and DC7 = '|| demande(7) ;
if cpt_zero = 1 then
jointure := 'C7 = DC7';
else
jointure := jointure || ' and C7 = DC7';
end if;
else
critere1 := critere1 || ' and DC7 is null';
end if;
demande(8) :=montant_1_CRI.DC8;
if demande(8) is not null then
cpt_zero := cpt_zero + 1;
critere1 := critere1 || ' and DC8 = '|| demande(8) ;
if cpt_zero = 1 then
jointure := 'C8 = DC8';
else
jointure := jointure || ' and C8 = DC8';
end if;
else
critere1 := critere1 || ' and DC8 is null';
end if;
demande(9) :=montant_1_CRI.DC9;
if demande(9) is not null then
cpt_zero := cpt_zero + 1;
critere1 := critere1 || ' and DC9 = '|| demande(9) ;
if cpt_zero = 1 then
jointure := 'C9 = DC9';
else
jointure := jointure || ' and C9 = DC9';
end if;
else
critere1 := critere1 || ' and DC9 is null';
end if;
sum_montant := montant_1_CRI.montant;
strsql := 'select VW_TBL_RES_UTILE.ID, Ordre, DC1, DC2, DC3, DC4, DC5, DC6, DC7, DC8, DC9, SUM(tbl_donnees.Montant) as montant from TBL_DONNEES
INNER JOIN VW_TBL_RES_UTILE on ' || jointure || ' where' || critere1 || ' group by VW_TBL_RES_UTILE.ID, VW_TBL_RES_UTILE.Ordre, DC1, DC2, DC3, DC4, DC5, DC6, DC7, DC8, DC9';
--dbms_output.put_line(strsql);
--dbms_output.put_line('C1 ' || demande(1) || ' C2 ' || demande(2) || ' C3 ' || demande(3) || ' C4 ' || demande(4) ||' C5 '
--|| demande(5) || ' C6 ' || demande(6) || ' C7 ' || demande(7) || ' C8 ' || demande(8) ||' C9 ' ||demande(9) ||' ');
open c_cur for strsql;
loop
fetch c_cur into C_final;
exit when c_cur%notfound;
ID_FIN := C_final.ID;
Ordre_tab := C_final.Ordre;
--calcul nouveau montant
pres_donnes :=resultat(Ordre_tab-1).pres_donnees;
montant1CRI :=resultat(Ordre_tab-1).montant;
montant_tot_CRI := pres_donnes / nombre * sum_montant;
montant_tot2 := montant_tot_CRI + montant1CRI;
resultat(Ordre_tab).montant := montant_tot2;
end loop;
close c_cur;
-- mise à zero des donnees
cpt_zero := 0;
critere1 := '';
jointure := '';
end loop;
--update final
for i in 0..cpt_res-1 loop
update TBL_RES set TBL_RES.montant = resultat(i).montant where resultat(i).ID=TBL_RES.ID;
end loop; |
Partager