Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Issue with materialized view (ORA-02345)

M.R.Apr 23 2014 — edited Apr 23 2014

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.

This post has been answered by unknown-7404 on Apr 23 2014
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 21 2014
Added on Apr 23 2014
1 comment
302 views