Hello,
I am trying to create a materialized view based on the following function:
CREATE OR REPLACE function RBS_USER.dynamic_pivot return sys_refcursor
as
sql_query varchar2(8000);
p_cursor sys_refcursor;
begin
for x in (select distinct report_mm from UC_SOURCE_CUR_ACCT_CLASSIF order by 1)
loop
sql_query := sql_query || '''' || x.report_mm || ''' as "' || to_char(x.report_mm,'mm/dd/yyyy') || '", ';
end loop;
sql_query := 'select * from (
select UC_BUSINESS_TYPE, PRODUCT_PORTFOLIO, REVENUE, REPORT_MM FROM UC_SOURCE_CUR_ACCT_CLASSIF
)
pivot
(
sum(revenue)
for report_mm in (' || substr(sql_query,1,length(sql_query)-2) || '))';
open p_cursor for sql_query;
return p_cursor;
end;
I am getting ORA-02345: cannot create a view with column based on CURSOR operator.
How can I re-write the code in order to use it to generate a materialized view?
Maybe using a PIPELINED function? But the problem is I don't know beforehand the return type as it can be variable (depends on a range of months in table UC_SOURCE_CUR_ACCT_CLASSIF that is unknown.
Thank you,
M.R.