I have a function where i am summing the value of all sale_lines attached to a sale_head by sale_number. The problem is, the function will only return one sum, whereas I need it to return all sale_head sums in a specific time frame...
create or replace function sale_line_accounts
return number is
total_value_all number(38, 2);
value_sales number(12, 2);
last_month date;
this_month date;
sumPrice number(12,2);
-- type array_s is varray(200) of varchar2(30);
-- sums array_s := array_s();
begin
--------------------------------------
last_month := to_date('01/08/16');
this_month := to_date('03/08/16');
--------------------------------------
FOR headers IN
(
select sale_num, sale_date, status
from sale_head
where status = 'S' AND sale_date BETWEEN last_month AND this_month
) LOOP
-------------------------------------------
--sums.extend();--extend array
sumPrice:= 0;
FOR lines IN
(
select sale_num, quantity, actual_price
from sale_line
where sale_num = headers.sale_num
)LOOP
sumPrice := sumPrice + (lines.quantity * lines.actual_price);
dbms_output.put_line(sumPrice);
-- sums(sumPrice) := lines.sale_num;
END LOOP;
------------------------------------------
END LOOP;
-------------------------------------------
return sumPrice;
END;
/
the commented code was meant to create a collection or something? Please help!!