I need to create a report which retrieve expenses for the last 12 months. Depends on the day I execute my report the name of the columns of my report will change (for example if I execute the report in JUL, it should retrieve twelve columns with the expenses in JUN, MAY, APR, MARCH. The name of the columns are the last 12 months).
The following PL/SQL code creates a view with dinamic name columns depending on the sysdate.
DECLARE
vSQL VARCHAR2(4000);
BEGIN
vSQL := 'CREATE OR REPLACE VIEW IFSAPP.RLDateTest AS SELECT
ip.part_no,
IFSAPP.RD_PURCH_DEMAND_QTY_ISSUE_API.Get_Avr_Usage_Per_Month(ip.contract,ip.part_no ,to_char(sysdate, ''MM'')-1) ' || **SUBSTR(ADD_MONTHS(SYSDATE, -1),4,3)** ||
', IFSAPP.RD_PURCH_DEMAND_QTY_ISSUE_API.Get_Avr_Usage_Per_Month(ip.contract,ip.part_no ,to_char(sysdate, ''MM'')-2) ' || **substr(ADD_MONTHS(SYSDATE, -2),4,3)** || ' FROM ifsapp.inventory_part ip WHERE ip.contract = ''S03'' ';
EXECUTE IMMEDIATE vSQL;
END;
(|| SUBSTR(ADD_MONTHS(SYSDATE, -1),4,3) || is the alias of each colum)
The point is that once I execute my report, it should create the view and show all its rows. For that I had thought of using pipelined (to create a type table consisting of the result of my view and this would let me do SELECT * FROM TABLE(getView())) in my report.
My problem is that as the name of the columns of my view are not always the same I can't create my type table using pipelined.
Any idea how could do that or any other solution which let me use my view in a select statment?
Many thanks.