create or replace function bugunku_deger(ptarih date,ptutar number) return number is
deger number(18,2);
cursor c1 is
select a.tuik_ufe,a.tuik_tufe,nvl(a.mazot,0) mazot
from nakliye.enflasyon_table a
where a.yil||'-'||a.ay>=to_char(ptarih,'yyyy-mm')
order by a.yil,a.ay;
kayit c1%rowtype;
oran number;
begin
  deger:=ptutar;
  open c1;
  loop
     fetch c1 into kayit;
     exit when (c1%notfound);
     if kayit.mazot>0 then
       oran:=(((kayit.tuik_ufe+kayit.tuik_tufe)/2)/100/2)+(kayit.mazot/2/100);
       oran:=1+oran;
       deger:=round(deger*oran,2);
     else
       oran:=((kayit.tuik_ufe+kayit.tuik_tufe)/2)/100;
       oran:=1+oran;
       deger:=round(deger*oran,2);
     end if;
  end loop;
  close c1;
return(deger);
end;
