Fonction SOMMEPROD en PL/SQL
Bonjour
je suis un debutant PL/sql.
j'essaie d'ecreire une fonction qui permet de faire le même calcul que la fonction SOMMEPROD de excel ,donc j'ai ecrit cette fonction:
Code:
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
|
create or replace
function Nombre_mois_cotise_entree(garantie in bp_garantie.bp_garantie_nom%type,
typeresp in bp_garantie.bp_garantie_responsable_top%type,
segment_nom in bp_segment.bp_segment_nom%type,
generation in bp_generation.bp_generation_nom%type,
annee in bp_data_commerciale.bp_data_com_annee%type)
return number
as
entree number;
mois number;
i number;
nombre_moy number;
cursor c1 is
select
t1.bp_data_com_mens_in as entree,
t1.bp_data_com_mens_mois as num_mois
from
bp_data_commerciale_mensuel t1
inner join bp_garantie t2 on t2.bp_garantie_id = t1.bp_data_com_mens_gar_id
inner join bp_generation t3 on t1.bp_data_com_generation_id=t3.bp_generation_id
inner join bp_gamme t4 on t4.bp_gamme_id=t2.bp_garantie_gamme_id
inner join bp_segment t5 on t5.bp_segment_id=t4.bp_gamme_segment_id
where
t2.bp_garantie_nom=garantie
and
t2.bp_garantie_responsable_top=typeresp
and
t5.bp_segment_nom=segment_nom
and
t3.bp_generation_nom=generation
and
t1.bp_data_com_mens_annees=annee;
cursor c2 is
select
sum(t1.bp_data_com_mens_in) as totale
from
bp_data_commerciale_mensuel t1
inner join bp_garantie t2 on t2.bp_garantie_id = t1.bp_data_com_mens_gar_id
inner join bp_generation t3 on t1.bp_data_com_generation_id=t3.bp_generation_id
inner join bp_gamme t4 on t4.bp_gamme_id=t2.bp_garantie_gamme_id
inner join bp_segment t5 on t5.bp_segment_id=t4.bp_gamme_segment_id
where
t2.bp_garantie_nom=garantie
and
t2.bp_garantie_responsable_top=typeresp
and
t5.bp_segment_nom=segment_nom
and
t3.bp_generation_nom=generation
and
t1.bp_data_com_mens_annees=annee;
begin
nombre_moy:=0;
i:=0;
for dcomrec in c1
loop
entree:=entree+dcomrec.entree;
mois:=mois+dcomrec.num_mois;
if dcomrec.num_mois=i+1 then
nombre_moy:=nombre_moy + entree *(12-i);
end if;
i:=i+1;
end loop;
for totale_entree in c2
loop
nombre_moy:= nombre_moy / totale_entree.totale;
end loop;
return nombre_moy;
end; |
A la compilation il n'y a pas d'erreur mais quand je l'appelle elle me retourne rien du tout ma question est :
- est ce qu'il y a une fonction oracle qui fait la meme chose que SOMMEPROD
- Sinon qu'elle peut m'aider à l'ecrire
Merci