Materialized View creation  advice and SQL advice

I want to create a materialized view for the table below. The materialized view should query data from only this table and i want to join 2 rows to one.
The key for the joins are the column internal_correlation_id which is unique for request/response pair.
The table is updated every day with 2 million rows.
What type of materialized view should i use and how can i query to get one row?
CREATE TABLE EVENT (
       caller_id                              VARCHAR2(255)          NOT NULL
     , service_id                         VARCHAR2(255)          NOT NULL
     , country_code                         VARCHAR2(2)
     , internal_correlation_id                  VARCHAR2(255)          NOT NULL  -- Unique for request response pair
     , received_date                         DATE                    NOT NULL
     , status                              VARCHAR2(20)
     , queue_name                         VARCHAR2(255)          NOT NULL
     , USER_ID                              VARCHAR2(50)
     , engine_id                         VARCHAR2(50)
     , tracking_correlation_id                  VARCHAR2(2000)
     , mnc                              VARCHAR2(20)
     , mcc                              VARCHAR2(20)
     , request_type                         VARCHAR2(50)  -- REQUEST or RESPONSE
     , app_id                              VARCHAR2(50)
     , failure_code                         VARCHAR2(50)
     , failure_string                            VARCHAR2(255)
     , created_date                          DATE DEFAULT SYSDATE
    , updated_date                              DATE DEFAULT SYSDATE
    DB release 11G release 1
Edited by: Alekons01 on Mar 24, 2012 2:43 PM

Anyway, I don't believe you will be able to create MV with fast refresh. MV with complete refresh:
CREATE MATERIALIZED VIEW event_mv
  BUILD IMMEDIATE
  REFRESH COMPLETE ON DEMAND
  AS
    SELECT  e1.caller_id req_caller_id,
            e1.service_id req_service_id,
            e1.country_code req_country_code,
            e1.internal_correlation_id req_internal_correlation_id,
            e1.received_date req_received_date,
            e1.status req_status,
            e1.queue_name req_queue_name,
            e1.user_id req_user_id,
            e1.engine_id req_engine_id,
            e1.tracking_correlation_id req_tracking_correlation_id,
            e1.mnc req_mnc,
            e1.mcc req_mcc,
            e1.request_type req_request_type,
            e1.app_id req_app_id,
            e1.failure_code req_failure_code,
            e1.failure_string req_failure_string,
            e1.created_date req_created_date,
            e1.updated_date req_updated_date,
            e2.caller_id rsp_caller_id,
            e2.service_id rsp_service_id,
            e2.country_code rsp_country_code,
            e2.internal_correlation_id rsp_internal_correlation_id,
            e2.received_date rsp_received_date,
            e2.status rsp_status,
            e2.queue_name rsp_queue_name,
            e2.user_id rsp_user_id,
            e2.engine_id rsp_engine_id,
            e2.tracking_correlation_id rsp_tracking_correlation_id,
            e2.mnc rsp_mnc,
            e2.mcc rsp_mcc,
            e2.request_type rsp_request_type,
            e2.app_id rsp_app_id,
            e2.failure_code rsp_failure_code,
            e2.failure_string rsp_failure_string,
            e2.created_date rsp_created_date,
            e2.updated_date rsp_updated_date
      FROM  event e1,
            event e2
      WHERE e2.internal_correlation_id = e1.internal_correlation_id
        AND e1.request_type = 'REQUEST'
        AND e2.request_type = 'RESPONSE'
/SY.

Similar Messages

  • Materialized View - creation and schedule (To automate Refresh)

    Hi All,
    I have one table based on SQL Query (multiple tables) and loading data every day through procedure.
    When I execute the procedure is taking lot of time to load data. That’s why I am planning to create Materialized view to refresh the data in a table every day at some point of time (ex:-9.00 am).
    Exclude procedure and materialized view are there any ways to refresh the data?
    Can you and all please help me to create materialized view and schedule (Automate refresh).
    begin
    insert into CLAIMS_PRODUCT_TAB
    select
    substr(at.ATN_VOUCHER_NUMBER,1,6) as BRANCH,
    t.MONTH_NAME as MONTH,t.FISCAL_YEAR as YEAR,
    bb.ACC_ACCOUNT_TYPE as TYPE,
    aa.ACC_DEPARTMENT_CODE as DEPT,
    pr.PRODUCT_NAME as PRODUCT,
    case bb.ACC_ACCOUNT_TYPE when '1301' then 'Claims Paid' when '5383' then 'Claims OS' end as HEAD,
    case aa.ACC_DEPARTMENT_CODE when '31' then 'OD' when '32' then 'TP' when '39' then 'TP Pool' end as DEPT_NAME,
    count(distinct at.CLAIM_ID) as CLAIMS,
    --count( distinct at.POLICY_ID) as POLICIES,  
    sum(atd.ATD_CREDIT_AMOUNT - atd.ATD_DEBIT_AMOUNT) as totals
    from
    ACCOUNTING_TRN_DETAIL atd,time t,
    ACCOUNT bb,
    ACCOUNT aa,claim c, policy p,product pr,
    accounting_transaction at
    where bb.ACC_ACCOUNT_ID = aa.ACC_ACC_ACCOUNT_ID
    and at.CLAIM_ID = c.CLAIM_ID
    and c.POLICY_ID = p.POLICY_ID
    and p.PRODUCT_ID = pr.PRODUCT_ID
    and aa.ACC_ACCOUNT_ID = atd.ACC_ACCOUNT_ID
    and atd.ATN_ACCOUNTING_TRANSACTION_ID = at.ATN_ACCOUNTING_TRANSACTION_ID
    and trunc(at.ATN_TRANSACTION_DATE) = t.CAL_DATE
    and (bb.ACC_ACCOUNT_TYPE in ('1301','5383'))
    group by substr(at.ATN_VOUCHER_NUMBER,1,6)
    ,t.MONTH_NAME
    ,t.FISCAL_YEAR,bb.ACC_ACCOUNT_TYPE
    ,aa.ACC_DEPARTMENT_CODE
    ,pr.PRODUCT_NAME
    , case bb.ACC_ACCOUNT_TYPE when '1301' then 'Claims Paid' when '5383' then 'Claims OS' end
    ,case aa.ACC_DEPARTMENT_CODE when '31' then 'OD' when '32' then 'TP' when '39' then 'TP Pool' end );
    end;
    Thanks and Regards
    Venkat

    Is the MV and the source tables on the same database? If this is a remote MV, then check the source site if there are any issues (TEMP, UNDO space issues).

  • Need to refresh materialized view from procedure and pl/sql block

    Hi,
    I need to refresh materialized view (complete refresh)from procedure and pl/sql block .can some one help.
    MV name:MV_DGN_TEST_SESSION
    Thanks,
    Rajasekhar

    dbms_mview.REFRESH ('MV_DGN_TEST_SESSION', 'C');Regards,
    Mahesh Kaila
    Edited by: user4211491 on Dec 1, 2009 10:41 PM

  • Materialized View  with Joins and Possibilities of Partitioning

    Hi,
    We have a materialized view which has a data to query around 12 gb. The query goes some thing like
    this.
      Select a.c1,a.c2,b.c1,b.c2,c.c1,c.c2
      from a,b,c
      where a.c1=b.c1
      --and the where condition goes on...
      --i.e Basically joining 3 different tables with complex join conditions but without any group functions and subqueries.
       Now i have few questions here.
    Firstly as the Mview is created with joins we will have to create separate logs for each tables and we have did the same. The logs are created with rowid and sequence for better performance during refresh.
    Question No 1
    Is this is a best approach for materializing a query with complex join conditions. Or Is it better to make 3 different materialized views for each 3 tables and join those 3 MViews and write a query for my report. I ask this question just to make sure the refresh time is brought down by this method. But as such as we have created 3 different logs for 3 tables the refresh must be happening separately.
    Question No 2
    Data is likely to grow faster and faster on this. So we have a idea of making this a partitioned Mview. Can the Pro's advice me on this and suggest me the right practice for the same and help me to correct links from where i can pick a example and continue from there.
    Question No 3
    How to find whether the materialized view has refreshed on a fast mode or complete mode after the last refresh.
    Apart from querying and checking the rowid which i feel is quiet cumbersome for a mview with a data volume like what we have. By default when i see the info in TOAD for this Mview it shows Refresh Mode as "Force". But how to ascertain this.
    Thanks in anticipation for a good round of discussion

    Hi,
    We have a materialized view which has a data to query around 12 gb. The query goes some thing like
    this.
      Select a.c1,a.c2,b.c1,b.c2,c.c1,c.c2
      from a,b,c
      where a.c1=b.c1
      --and the where condition goes on...
      --i.e Basically joining 3 different tables with complex join conditions but without any group functions and subqueries.
       Now i have few questions here.
    Firstly as the Mview is created with joins we will have to create separate logs for each tables and we have did the same. The logs are created with rowid and sequence for better performance during refresh.
    Question No 1
    Is this is a best approach for materializing a query with complex join conditions. Or Is it better to make 3 different materialized views for each 3 tables and join those 3 MViews and write a query for my report. I ask this question just to make sure the refresh time is brought down by this method. But as such as we have created 3 different logs for 3 tables the refresh must be happening separately.
    Question No 2
    Data is likely to grow faster and faster on this. So we have a idea of making this a partitioned Mview. Can the Pro's advice me on this and suggest me the right practice for the same and help me to correct links from where i can pick a example and continue from there.
    Question No 3
    How to find whether the materialized view has refreshed on a fast mode or complete mode after the last refresh.
    Apart from querying and checking the rowid which i feel is quiet cumbersome for a mview with a data volume like what we have. By default when i see the info in TOAD for this Mview it shows Refresh Mode as "Force". But how to ascertain this.
    Thanks in anticipation for a good round of discussion

  • Materialized view creation issue

    I am running into an issue and trying to ascertain issue.
    Scenario:
    I have 2 MV creation scripts. The MV is supposed to get populated by connection from schema to another schema USING DB Links.
    Basically, SAME HOST, SAME RAC DATABASE, just separate schemas.
    The MV creations are just hanging. I see NO alert log mentions. I ran  a SQL trace and yes, I see:
    call count       cpu elapsed       disk query    current        rows
    Parse 0      0.00 0.00 0          0 0           0
    Execute   1011 1.40 73.80 0 0 0           0
    Fetch 1010      1.08 317.57 0 0 0        1010
    total 2021      2.49 391.38 0 0 0        1010
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 109     (recursive depth: 2)
    Elapsed times include waiting on following events:
      Event waited on Times Max. Wait  Total Waited
      ---------------------------------------- Waited  ----------  ------------
      SQL*Net message to dblink 2022 0.00          0.00
      SQL*Net message from dblink 2021 0.46        242.58
    Understandable, but when I do a selective query, the results come back pretty much within 5 seconds.
    DB version is 11.2.0.3.   Is there a BUG that I should know about?
    Here is a snippet:
    CREATE MATERIALIZED VIEW "SCHEMA"."MV_NAME_MV" USING INDEX REFRESH COMPLETE ON DEMAND AS (SELECT distinct mapguide_persons(pl.location_code) "FULL_NAME_COSTCENTER",
    mapguide_jobemp(pl.location_code) "TRUNCNAME_JOB",
    mapguide_empnum(pl.location_code) "FULLNAME_EMPNUMBER_PHONE",
    mapguide_english(pl.location_code) "ENGLISH_NAME_COSTCENTER",
    pl.function_type_lookup_code "FUNCTION_TYPE_LOOKUP_CODE",
    pl.location_code "LOCATION_CODE",
    pl.org_id "ORG_ID"
    FROM [email protected] pl
    WHERE pl.function_type_lookup_code not in ('VALUE','CONSULT')
    and sysdate between pl.active_start_date and active_end_date);
    *Network netstat –in output **
    netstat -in
    Kernel Interface table
    Iface       MTU Met    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
    eth0       1500   0 58751025      0 0      0 27335255 0      0      0 BMRU
    eth0:1     1500 0      - no statistics available - BMRU
    eth0:2     1500 0      - no statistics available - BMRU
    eth1       1500   0 5569305513      0 0      0 4365204661 0      0      0 BMRU
    eth2       1500   0 146061981      0 0      0 270589939 0      0      0 BMRU
    eth2:1     1500 0      - no statistics available - BMRU
    lo 16436   0 31731571 0      0      0 31731571      0 0      0 LRU
    The above just hangs and spins its wheels…
    Any ideas are appreciated…
    thanks

    JCGO wrote:
    The above just hangs and spins its wheels…
    And what happens when you issue just the underlying select:
    SELECT distinct mapguide_persons(pl.location_code) "FULL_NAME_COSTCENTER",
    mapguide_jobemp(pl.location_code) "TRUNCNAME_JOB",
    mapguide_empnum(pl.location_code) "FULLNAME_EMPNUMBER_PHONE",
    mapguide_english(pl.location_code) "ENGLISH_NAME_COSTCENTER",
    pl.function_type_lookup_code "FUNCTION_TYPE_LOOKUP_CODE",
    pl.location_code "LOCATION_CODE",
    pl.org_id "ORG_ID"
    FROM [email protected] pl
    WHERE pl.function_type_lookup_code not in ('VALUE','CONSULT')
    and sysdate between pl.active_start_date and active_end_date
    SY.

  • Materialized view creation taking long time

    Hi All,
    We are creating a dimensional OLAP model with the Materialized views. In that we are having 7 dimensions and 1 fact table. I have created all the dimensions with the materialized views with out any problem. But when im trying to create my Fact materialized view it is running for 14 hours and is still running. I'm waiting to see when it will complete. The select statement in the Fact MV returns only 19 records and that too in seconds. But when i use the same select statement for MV creation it is taking a long time. I dont know how long it gonna take. How can i reduce this long running time. Mean while my fact MV is having nearly 15 joins with other physical tables and dimensions.
    Thanks in advance,
    Karthick

    Hi all,
    Thanks for your reply..
    I think i dint clearly mention my problem..
    The select statement for the MV will return 19 records. But when im trying to create the MV it is taking quite a long time. it ran for >14 hours but still it dint create a MV. Why is it happening like this? Is it possible to increase the performance.
    Thanks,
    Karthick

  • Materialized View creation with REFRESH FAST

    Hello ,
    Please see below case,
    TABLE A1(partitioned range+list)
    COLUMN C1  -- Primary key
    COLUMN C2  -- NUMBER
    TABLE D1
    COLUMN C1 -- PRIMARY KEY
    created MV log as below
    CREATE MATERIALIzED VIEW LOG ON A1 WITH ROWID,PRIMARY KEY INCLUDING NEW VALUES;
    CREATE MATERIALIzED VIEW LOG ON D1 WITH ROWID,PRIMARY KEY INCLUDING NEW VALUES;
    Trying to create MV like below:
    CREATE MATERILIZED VIEW mv1test
                                    REFRESH FAST ON COMMIT
    AS
    Select
    FROM A1,
                            D1
                    WHERE A1.C1 = D1.CI
    AND A1.C2 IS NOT NULL;
    It gives below error message:
    ORA-12052: cannot fast refresh materialized view schema.mv1test
    12052. 00000 -  "cannot fast refresh materialized view %s.%s"
    *Cause:    Either ROWIDs of certain tables were missing in the definition or
               the inner table of an outer join did not have UNIQUE constraints on
               join columns.
    *Action:   Specify the FORCE or COMPLETE option. If this error is got
               during creation, the materialized view definition may have be
               changed. Refer to the documentation on materialized views.
    However ,as discussed in earlier thread i checked all general restrictions of the 'Refresh fast' approach for join.
    Restrictions on Fast Refresh on Materialized Views with Joins Only
    Defining queries for materialized views with joins only and no aggregates have the following restrictions on fast refresh:
    1) They cannot have GROUPBY clauses or aggregates.
    2) Rowids of all the tables in the FROM list must appear in the SELECT list of the query.
    3)Materialized view logs must exist with rowids for all the base tables in the FROM list of the query.
    4)You cannot create a fast refreshable materialized view from multiple tables with simple joins that include an object type column in the SELECTstatement.
    As per above restrictions ,
    1) Group by clause is not present
    2)i do not understand 2nd point , i have added a1.rowid  and d1.rowid in  select statement of MV, but got same error.
    3) observed same as 2nd point.
    4)we have CLOB column in select list. Tried removing this column but got same error.
    Please do let me know any workaround on this.
    Thanks in advanced ..
    PM

    Basic Materialized Views show how to analyse MVs using dbms_mview. I'm not sure about creating MVs on partitioned tables, that partition maintenance might cause problems

  • How to create materialized  view with parameter and index ?

    Hi all,
    i am using oracle 11g.
    i want to create  parameter materialized view  with two parameter (STORED_VALUE, LOV_NAME) with  an index .
    i have below view
    CREATE OR REPLACE FORCE VIEW SR_MY_TEST(DISPLAYED_VALUE, STORED_VALUE, LOV_NAME) AS
      SELECT  DISPLAYED_VALUE , LOVVALUE.STORED_VALUE , lovname.lov_name
               FROM (SELECT T.LOV_VALUE_ID,
          T.LOV_ID,
          T.ORG_ENTITY_ID,
          T.STORED_VALUE,
          T.DISPLAYED_VALUE,
          T.ENTERPRISE_ID
         FROM MS_QS_LIST_OF_VALUES_T T) lovvalue, ms_qs_lov_names lovname
              WHERE lovvalue.lov_id = lovname.lov_id
                AND lovvalue.org_entity_id = 1
                and LOVVALUE.ENTERPRISE_ID = 100000
                AND LOVNAME.ENTERPRISE_ID = 100000;
    i want to create index on   STORED_VALUE, LOV_NAME
    Thanks
    Damby

    No.AFAIK, there's nothing called as "parameterized MV".
    Materialized View store data like tables (and not like Views). So, does it make sense when you say - "table with parameters" ?
    Could you please explain your business requirement?
    What is the purpose behind those 2 parameters?

  • Why materialized view taking hours and yet not created

    hi,
    i am trying to create the following MV
    create materialized view MV1
    force on demand
    start with date 1 next date2
    AS
    select query 1--> complex query that return approcimately 2 millions rows
    union all
    select query2 --> complex query that returns 300K rowsit has been taking hours i.e > 4 hrs and still unable to create the MV
    w/o the create materialized view statement i am able to return the results from the union of the 2 queries
    what might be the possibility ?
    tks & rdgs

    Issue could be due to the complexity of your query..Even i faced the same issue when i worked on materialized views.It was taking too long to create materialized view and then we splitted the query and created two materialized views.
    Finally created a View for those MV's.You can also try the same
    Materialized View Log
    When you create a materialized view using the FAST option you will need to create a view log on the base tables.A fast refresh uses materialized view logs to update only the rows that have changed since the last refresh.
    When DML changes are made to the master table's data, Oracle stores rows describing those changes in the materialized view log and then uses the materialized view log to refresh materialized views based on the base table. This process is called an incremental or fast refresh.Without a materialized view log, Oracle must reexecute the materialized view query to refresh the materialized view. This process is called a complete refresh.Usually, a fast refresh takes less time than a complete refresh.
    You can go through the below link
    http://www.lc.leidenuniv.nl/awcourse/oracle/server.920/a96567/repmview.htm
    Thanks
    Suni

  • Materialized View - "use log" and its "master table" assigned

    Oracle 10 g R2. Here is my script to create a mv, but I noticed two interestes properties by EM
    CREATE MATERIALIZED VIEW "BAANDB"."R2_MV"
    TABLESPACE "USERS" NOLOGGING STORAGE ( INITIAL 128K) USING INDEX
    TABLESPACE "BAANIDX" STORAGE ( INITIAL 256K)
    REFRESH FORCE ON COMMIT
    ENABLE QUERY REWRITE AS
    SELECT CM.ROWID c_rid, PC.ROWID p_rid, CM."T$CWOC", CM."T$EMNO", CM."T$NAMA", CM."T$EDTE", PC."T$PERI", PC."T$QUAN", PC."T$YEAR", PC."T$RGDT"
    FROM "TTPPPC235201" PC , "TTCCOM001201" CM
    WHERE PC."T$EMNO"(+)=CM."T$EMNO"
    In EM, the MV list shows a column - "Can Use Log".
    1. What does it mean?
    2. Why it only says yes, when I used above codes to create the MV; but says "NO" when I created the MV by "OUT JOIN"? no matter is "LEFT.." or "RIGHT JOIN"
    3. I also noticed that there is a column - "master table" and it always shows the name of the last table on the from list. Why? More important, does it matter to process. It shows the same table name when I use the "OUT JOIN" clause in from
    I have created mv log on each master table with row_id.

    Review the rules for your version of Oracle, you didn't think it important to name it, with respect to when you can do FAST REFRESH and when it can use REFRESH LOGs.

  • MATERIALIZED VIEW ORA-12006 and ORA-08103

    We have an old 9.2.0.6 database which uses materialized views to access information from other systems via database links. One of these views though will no longer refresh, the others are OK including ones using the same database link and source system.
    When we try to refresh get:
    CREATE MATERIALIZED VIEW <user>.<materialized view>
    REFRESH FORCE
    AS SELECT *
    FROM <source user>.<source table>@<database link>
    AS SELECT *
    ERROR at line 3:
    ORA-12006: a materialized view with the same user.name already exists
    drop MATERIALIZED VIEW <user>.<materialized view>
    ERROR at line 1:
    ORA-08103: object no longer exists
    Obviously we can't rename the view and because of various restrictions I can't upgrade the database, we are in the process of migrating it to 11g.
    Does anyone have a magic bullet to resolve this as I have been looking around and haven't found an answer as yet.

    Sorry you think the results are confusing but they are the results, obviously I have to protect exact names etc...
    Materialized View system:
    Shows other views for other source systems but not the ones for this source system.
    It shows these ones as an object_type of TABLE in dba_objects even though they were created as materilized views.
    Source system select:
    OBJECT_NAME OBJECT_TYPE OWNER
    <table name> TABLE <table owner>
    <table name> SYNONYM PUBLIC
    If I use a new name yes it does resolve the issue but I don't want to use a different name if possible as either the application guys have to change some code or I will have to build in another level of synonyms to translate the new name. At the end of the day if this is the only solution!

  • Developing database views between Oracle and SQL Server tables

    I am on Oracle 10.2, my organization has many SQL Server databases as well and has now made
    SQL server as company standard so many new databases will be developed in SQL Server. It is of course
    not possible to convert all Oracle databases to SQL Server, so a mix environment will exist. Two questions:
    1.     Is it possible to develop database views in Oracle (10g in my case) which join Oracle tables with tables in SQL Server 2008? If yes, how. I have seen some heterogeneous connectivity setup to connect SQL Server to Oracle, but not sure whether it is possible to develop a database view across two databases.
    2.     I know it is not a SQL Server forum, but many DBA’s know both Oracle and SQL Server. Is it possible to develop views in SQL Server (SQL Server 2008 R2 in my case) which join Oracle 10g and SQL Server 2008 tables? I know in SQL Server, there is way to set up linked servers, but do not know whether it is possible to develop views.
    Thanks a lot for your insight.

    You can create views that join local Oracle tables and remote SQL Server tables. I'm pretty sure you can do the reverse as well but I haven't personally done it.
    However, I would be very concerned about the performance you'd get if you created that sort of view. You'd very frequently end up in a situation where Oracle has to pull all the data in the remote table across the database link in order to apply predicates and join the data locally. That could be disastrous from a performance standpoint.
    Justin

  • Materialized views in 8i and 9i

    Hi All,
    I wanted to know the differences/comparison of MVs in 8i and 9i versions.
    Can you please lead me to some documentation if available on this?
    Thanks in advance...
    BRK

    I would suggest you check out DbEncrypt for Oracle from www.appsecinc.com. You get download a free evaluation versions. It provides a fully functional encryption system including key manangement, transparent encryption, etc...

  • Materialized view creation.

    hi experts.
    I have a requirement wherein I need to create a mview based on a single table.Mview is going to be a complex mview(uses correlated sub-queries in SELECT) and the source table resides in some other database. I need this mview refreshed once for a day.
    I created mview as BUILD IMMEDIATE REFRESH COMPLETE START WITH sysdate NEXT sysdate+1. Is this fine ?
    Please suggest if there is much efficient way of creating mview in this case?
    Thank you.

    How large is the source table? Have you considered the time it will take to complete the refresh?

  • Cannot create Materialized View using PL/SQL procedure

    Hello,
    I have a question related to Materialized View creation.
    I have a stored procedure that creates materialized view. When trying to run this procedure I get insufficient privileges error: ORA-01031.
    When I run content of this procedure as anonymous PL/SQL block them materialized view is created without any complications.
    Can you please advice me on that topic?
    Is it even possible to create materialized view in stored procedure as I haven't found an info on it.
    Thanks
    Petr

    Hi chudapet,
    Whenever you do operation in procedure you need to have direct grants and not via a role.
    Most probably the grant to create materialized view is available via a role to your user.
    Assign direct grant to the user:
    grant create materialized view to scott;
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Maybe you are looking for