PL/SQL (MOSC)

MOSC Banner

PL/SQL function to calculate average monthwise for a given date range

edited Jan 14, 2015 4:18AM in PL/SQL (MOSC) 6 commentsAnswered ✓

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.

Howdy, Stranger!

Log In

To view full details, sign in to My Oracle Support Community.

Register

Don't have a My Oracle Support Community account? Click here to get started.

Category Leaderboard

Top contributors this month

New to My Oracle Support Community? Visit our Welcome Center

MOSC Help Center