PL/SQL function to calculate average monthwise for a given date range
Suppose on 1st jan count is 20, 2nd jan count is 12 , 3rd jan count is 0 , ............................. ........... .................. 31st jan count is 17
I need a function which can find the average monthwise .In this case it should be 20+12+17/3 because I dont want to use the day which has count 0
I tried this:-
create function(p_date IN Date)
return number is
cursor c_num is
select count(distinct attribute8) from mtl_material_transactions where trunc(transaction_date)=p_date;
l_num number:=0
begin
open c_num;
fetch c_num into l_num;
close c_num;
return sum(l_num);
end;
But it is not working as per my requirement.Please help me.I need to find monthwise average for a given date range say 01-April-2013 to 31st Mar-2014.