Materialized Views query is ZERO count

When doing refreshes the Mviews come up as ZERO count...
any option we can do to prevent this?
DB is 10.2.0.5
thanks

You possibly have another job (scheduled through DBA_JOBS or DBA_SCHEDULER_JOBS or cron or an external scheduler OR initiated by a user or application) that does the refresh (truncate and refresh) between the time you complete a refresh and you query 2 hours later ?
Possibly the source has no data at the next refresh so the next refresh causes the MV to be Zero count.
Then, at the third execution, the source has data so the MV now again appears with data ?!
Hemant K Chitale

Similar Messages

  • Spatial vs. materialized views/query rewrite

    Dear all,
    we are trying to use Spatial (Locator) functionality together with performance optimization using materialized views and query rewrite, and it does not seem to work. Does anybody has experience with this?
    The problem in more detail:
    * There is a spatial attribut (vom Typ GEOMETRY) in our table;
    * we define a materialized view on that table;
    * we run a query that could be better answered using the materialized view with query rewrite;
    *the optimizer does not choose the plan using the materialized view, query rewrite does not take place;
    This happenes, even if neither the materialized view, nor the query contains the spatial attribut.
    The explanation given by the procedure DBMS_MVIEW.Explain_Rewrite is:
    "QSM-01064 query has a fixed table or view Cause: Query
    rewrite is not allowed if query references any fixed tables or views"
    We are using Oracle 9R2, Enterprise Edition, with locator. Nevertheless, it would also be interesting, if there is any improvement in 10g?
    A more complicated task, using materialized views to optimize spatial operations (e.g., sdo_relate) would also be very interesting, as spatial joins are very expensive operations.
    Thanks in advance for any comments, ideas!
    Cheers,
    Gergely Lukacs

    Hi Dan,
    thanks for your rapid response!
    A simple example is:
    alter session set query_rewrite_integrity=trusted;
    alter session set query_rewrite_enabled=true;
    set serveroutput on;
    /* Creating testtable */
    CREATE TABLE TESTTABLE (
    KEY1 NUMBER (4) NOT NULL,
    KEY2 NUMBER (8) NOT NULL,
    KEY3 NUMBER (14) NOT NULL,
    NAME VARCHAR2 (255),
    X NUMBER (9,2),
    Y NUMBER (9,2),
    ATTR1 VARCHAR2 (2),
    ATTR2 VARCHAR2 (30),
    ATTR3 VARCHAR2 (80),
    ATTR4 NUMBER (7),
    ATTR5 NUMBER (4),
    ATTR6 NUMBER (5),
    ATTR7 VARCHAR2 (40),
    ATTR8 VARCHAR2 (40),
    CONSTRAINT TESTTABLE_PK
    PRIMARY KEY ( KEY1, KEY2, KEY3 ));
    /* Creating materialized view */
    CREATE MATERIALIZED VIEW TESTTABLE_MV
    REFRESH COMPLETE
    ENABLE QUERY REWRITE
    AS SELECT DISTINCT ATTR7, ATTR8
    FROM TESTTABLE;
    /* Creating statistics, just to make sure */
    execute dbms_stats.gather_table_stats(ownname=> 'TESTSCHEMA', tabname=> 'TESTTABLE', cascade=>TRUE);
    execute dbms_stats.gather_table_stats(ownname=> 'TESTSCHEMA', tabname=> 'TESTTABLE_MV', cascade=>TRUE);
    /* Explain rewrite procedure */
    DECLARE
    Rewrite_Array SYS.RewriteArrayType := SYS.RewriteArrayType();
    querytxt VARCHAR2(1500) :=
    'SELECT COUNT(*) FROM (
    SELECT DISTINCT
    ATTR8 FROM
    TESTTABLE
    i NUMBER;
    BEGIN
    DBMS_MVIEW.Explain_Rewrite(querytxt, 'TESTTABLE_MV', Rewrite_Array);
    FOR i IN 1..Rewrite_Array.count
    LOOP
    DBMS_OUTPUT.PUT_LINE(Rewrite_Array(i).message);
    END LOOP;
    END;
    The message you get is:
    QSM-01009 materialized view, string, matched query text
    Cause: The query was rewritten using a materialized view, because query text matched the materialized view text.
    Action: No action required.
    i.e. query rewrite works!
    /* Adding geometry column to the testtable -- not to the materialized view, and not to the query! */
    ALTER TABLE TESTTABLE
    ADD GEOMETRYATTR mdsys.sdo_geometry;
    /* Explain rewrite procedure */
    DECLARE
    Rewrite_Array SYS.RewriteArrayType := SYS.RewriteArrayType();
    querytxt VARCHAR2(1500) :=
    'SELECT COUNT(*) FROM (
    SELECT DISTINCT
    ATTR8 FROM
    TESTTABLE
    i NUMBER;
    BEGIN
    DBMS_MVIEW.Explain_Rewrite(querytxt, 'TESTTABLE_MV', Rewrite_Array);
    FOR i IN 1..Rewrite_Array.count
    LOOP
    DBMS_OUTPUT.PUT_LINE(Rewrite_Array(i).message);
    END LOOP;
    END;
    The messages you get are:
    QSM-01064 query has a fixed table or view
    Cause: Query rewrite is not allowed if query references any fixed tables or views.
    Action: No action required.
    QSM-01019 no suitable materialized view found to rewrite this query
    Cause: There doesn't exist any materialized view that can be used to rewrite this query.
    Action: Consider creating a new materialized view.
    i.e. query rewrite does not work!
    If this works, the next issue is to use materialized views for optimizing spatial operations, e.g., a spatial join. I can supply you with an example, if necessary (only makes sense, I think, after the first problem is solved).
    Thanks in advance for any ideas, comments!
    Cheers,
    Gergely

  • Materialized view query (Oracle 9i)

    I have dropped a materialized view query and trying to create the same with additional columns in the prebuilt table.
    Option - 1
    when Iam using a query in the materialized view query "select * from schema.table@link, with refresh mode fast option, the database throws an error " no table or view exists"
    Option - 2
    When Iam using a query in the materialized view query "select * from schema.table@link, with refresh mode option either complete or force, it gets created.
    I need to create the above materialized view query in the fast mode option, Please help.
    -bala

    Hi,
    Does a table named profit_mvw already exist?
    The following example illustrates the two steps required to register a user-defined table. First, the table is created, then the materialized view is defined using exactly the same name as the table. This materialized view sum_sales_tab is eligible for use in query rewrite.
    CREATE TABLE sum_sales_tab
    PCTFREE 0 TABLESPACE demo
    STORAGE (INITIAL 16k NEXT 16k PCTINCREASE 0) AS
    SELECT s.prod_id, SUM(amount_sold) AS dollar_sales,
    SUM(quantity_sold) AS unit_sales
    FROM sales s GROUP BY s.prod_id;
    CREATE MATERIALIZED VIEW sum_sales_tab
    ON PREBUILT TABLE WITHOUT REDUCED PRECISION
    ENABLE QUERY REWRITE AS
    SELECT s.prod_id, SUM(amount_sold) AS dollar_sales,
    SUM(quantity_sold) AS unit_sales
    FROM sales s GROUP BY s.prod_id;
    Regards,
    Simon

  • Materialized views - query rewrite -- optional joins & dimensions

    Hi,
    I've implemented a number of materialized views that are accessible via query rewrite.
    Most of these views make use of duplicate tables (DD_TIME table is joined via purchase, load, process, ... date columns)
    I've also created a dimension to make Oracle aware of the time relation (month is child of year...)
    The issue:
    --> If I create the mat. view with inner joins, query rewrite works with the dimensions, but I need to provide ALL joined tables in the query
    --> If I create the mat. view with outer joins, query rewrite works even with 1 joined table, but the dimension seems to be ignored
    How can I create 'optional' joins in the Mat. View while making use of dimensions for rollup?
    (the limitations on materialized view delta joins mentioned on [oracle docs|http://docs.oracle.com/cd/B28359_01/server.111/b28313/qradv.htm#autoId16] kinda has me worried)
    Example Mat. View:
    CREATE MATERIALIZED VIEW DA_REPOSITORY_MERCHANT_MM
    ... ENABLE QUERY REWRITE
    AS SELECT
    DDFPC.YEAR_NO,
    DDFPC.YEAR_MONTH,
    DDPUR.YEAR_NO,
    DDPUR.YEAR_MONTH,
    SUM( DF.TRANSACTION_AMOUNT )
    FROM DF_REP DF,
    DD_TIME DDFPC,
    DD_TIME DDPUR
    WHERE DF.FPC_DTE = DDFPC.DAY_DATE(+)
    AND DF.PUR_DTE = DDPUR.DAY_DATE(+)
    GROUP BY
    DDFPC.YEAR_NO,
    DDFPC.YEAR_MONTH,
    DDPUR.YEAR_NO,
    DDPUR.YEAR_MONTH
    Example query launched:
    SELECT
    DDFPC.YEAR_NO,
    SUM( DF.TRANSACTION_AMOUNT )
    FROM DF_REP DF,
    DD_TIME DDFPC
    WHERE DF.FPC_DTE = DDFPC.DAY_DATE
    GROUP BY
    DDFPC.YEAR_NO

    The problem was resolved by setting foreign keys in the fact table and making them not nullable + using inner joins.
    --> this informs oracle there can be no difference between a query without the dimensions and a query with the dimensions.
    As a result, the materialized view can contain 1 fact linked to 2 dimension tables, but the query rewrite will work for queries on the 1 fact joined with only 1 dimension

  • Create Materialized View ORA-01723: zero-length columns are not allowed

    I am trying to create a materialized view which derives a column from a function and I get: ORA-01723: zero-length columns are not allowed.
    I am using 10gR2 with the following definition (simple version):
    CREATE MATERIALIZED VIEW AS
    SELECT
    function_name(column_name) COLUMN_ALIAS
    FROM table_name;
    I have even tried to cast it like below:
    CREATE MATERIALIZED VIEW AS
    SELECT
    CAST(function_name(column_name) AS VARCHAR2(200)) COLUMN_ALIAS
    FROM table_name;
    My function does have an exception to return a value even if no values are found.
    I have looked all over for the solution. Does anyone have a way around this issue? I really need my function to derive the column as it has business rules which I cannot join into my materialized view definition. My only hope around this is to insert the values into a table and then create a materialized view from that table, I don't want to do that if someone has a solution around this.
    Any help would be greatly appreciated.
    Thank you,
    Kyle
    Edited by: Kyle Miller on Apr 19, 2011 8:28 AM

    Have you tried creating a table with the correct structure and then creating the materialized view based on the prebuilt table as described here...
    http://www.oaktable.net/content/ultra-fast-mv-alteration-using-prebuilt-table-option
    Cheers
    Ben

  • How to change Materialized View query?

    Hi all,
    sorry for this newbie question, but I'm not able to work out this matter...
    How can I change the query used by a materialized view without dropping an recreate all, and using another user(SYS in my case)?
    It looks like the command 'alter materialized view ...' does not allow this, am I wrong?
    thanks a lot
    aldo

    You quick answer saved me a lot of other unsuccessfully searches.
    thanks
    aldo

  • Materialized VIews Query

    Hi,
    I want to Insert a record in my table every time materilized view brings in a new record . Is this possible , if yes anyone please suggest solution.
    Thanks
    Aali

    Hi,
    check this link for TRIGGER on MV,
    Materialized View Trigger does not fire
    Also did you try creating a trigger on the TABLE which will INSERT into the TABLE where you want it to be inserted.
    Thanks

  • [Materialized View]: SUM(expr) without COUNT(expr)

    I have created one MV of type aggregation. when i used DBMS_MVIEW.EXPLAIN_MVIEW i found that "SUM(expr) without
    COUNT(expr)".
    I have used SUM(exp) function but i dont require count(exp) .
    Now due to "SUM(expr) without COUNT(expr)" reason my mv does not gets fast refresh
    after any DML on the base master table.
    What to do do now?
    Is there any alternative for that?
    I mean i want to use sum(exp) but not count(exp) and also want fast refresh when any DML applied on base master table.

    You have to add count(expr) to your MV . This is a requirment for fast refresh MV.
    Rgds

  • Materialized view with aggregates doing a fast refresh

    why is that i need to have count(*),count(<expressions used>) in my Materialized view Query with Aggregates?
    say mat view query is:
    select deptno,sum(sal) from emp,dept where emp.deptno,dept.deptno group by dname.cant do a fast refresh.
    BUT
    select deptno,sum(sal),count(*),count(sal) from emp,dept where emp.deptno,dept.deptno group by dname.Does a fast refresh.Why?
    Also its mentioned in manuals that count(*) and count(expr) is needed but it doesnt explain why.
    Thanks

    Thanks for the correction.I just wanted to simulate the query and it was a typing mistake.sorry for that.
    My query working fine with count(). If i understand it correctly it is to determine whether there should be an update or delete to MV in case of say delete on master table.that is, count is decremented on delete and if it becomes 0 then we need to delete that aggregated row from the MV,else it need to be updated even in case of delete.
    But this answers why count() is needed for coulmns in group by clause.
    Dont really see a need to have count() in case i m updating the measures as materilized view logs should take care of it.

  • MATERIALIZED view on two tables with Fast Refresh

    i Wanted to create MV on two tables with Fast refresh on commit.
    I followed below steps
    create materialized view log on t1 WITH PRIMARY KEY, rowid;
    create materialized view log on t2 WITH PRIMARY KEY, rowid;
    CREATE MATERIALIZED VIEW ETL_ENTITY_DIVISION_ASSO_MV
    REFRESH fast ON commit
    ENABLE QUERY REWRITE
    AS
    select A.ROWID B.ROWID,a.c1, DECODE(a.c1,'aaa','xxx','aaa') c2
    from t1 A
    join t2 b
    on AB.c1= CD.c2;
    i am getting below error.
    Error report:
    SQL Error: ORA-12054: cannot set the ON COMMIT refresh attribute for the materialized view
    12054. 00000 - "cannot set the ON COMMIT refresh attribute for the materialized view"
    *Cause:    The materialized view did not satisfy conditions for refresh at
    commit time.
    *Action:   Specify only valid options.
    Basically i want to take record in MV by joinig two tables and if both of the base tables will updated then record should reflect in materialised view.
    Please do the needfull.

    does the table support PCT? the other restrictions on joins look to be ok in your statement.
    maybe try creating first with on demand instead of commit to see does it create.
    http://docs.oracle.com/cd/B19306_01/server.102/b14223/basicmv.htm
    >
    Materialized Views Containing Only Joins
    Some materialized views contain only joins and no aggregates, such as in Example 8-4, where a materialized view is created that joins the sales table to the times and customers tables. The advantage of creating this type of materialized view is that expensive joins will be precalculated.
    Fast refresh for a materialized view containing only joins is possible after any type of DML to the base tables (direct-path or conventional INSERT, UPDATE, or DELETE).
    A materialized view containing only joins can be defined to be refreshed ON COMMIT or ON DEMAND. If it is ON COMMIT, the refresh is performed at commit time of the transaction that does DML on the materialized view's detail table.
    If you specify REFRESH FAST, Oracle performs further verification of the query definition to ensure that fast refresh can be performed if any of the detail tables change. These additional checks are:
    A materialized view log must be present for each detail table unless the table supports PCT. Also, when a materialized view log is required, the ROWID column must be present in each materialized view log.
    The rowids of all the detail tables must appear in the SELECT list of the materialized view query definition.
    If some of these restrictions are not met, you can create the materialized view as REFRESH FORCE to take advantage of fast refresh when it is possible. If one of the tables did not meet all of the criteria, but the other tables did, the materialized view would still be fast refreshable with respect to the other tables for which all the criteria are met.

  • Problem with Materialized Views in 10g

    Hi All,
    I am creating a Materialized View like
    CREATE MATERIALIZED VIEW mvname TABLESPACE SYSTEM BUILD IMMEDIATE REFRESH WITH ROWID FOR UPDATE AS ( SELECT a,b,c FROM table_a,table_b,table_c WHERE cond );
    I am getting an error
    SQL Error: ORA-12013: updatable materialized views must be simple enough to do fast refresh.
    Can anyone tell what is the problem?
    I have included rowid of all three tables in select clause.

    Hi,
    From Oracle Docs:
    ORA-12013: updatable materialized views must be simple enough to do fast refresh
    Cause: The updatable materialized view query contained a join, subquery, union, connect by, order by, or group by caluse.
    Action: Make the materialized view simpler. If a join is really needed, make multiple simple materialized views then put a view on top of them.
    Regards
    K.Rajkumar

  • Is materialized view available in Oracle SE ?

    Hi all,
    I have questions on materizlalized view :
    1) Is materialized view available in Oracle Standard Edition ?
    2) what is the meaning of "Materialized View Query Rewrite " ?
    Thank you very much,
    xtanto

    Hi all,
    I have questions on materizlalized view :
    1) Is materialized view available in Oracle Standard
    Edition ?http://www.oracle.com/technology/products/database/oracle11g/pdf/database-11g-product-family-technical-whitepaper.pdf
    >
    2) what is the meaning of "Materialized View Query
    Rewrite " ?http://download.oracle.com/docs/cd/B28359_01/server.111/b28313/qrbasic.htm#CIHDIEDI

  • 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

  • Help materialized view

    Hi,
    i need to create materialized fast refresh view from 3 base tables.I was tried but below error coming,since i informed to my manger not possible.but his not agrees.Could somone help to create materialized view with fast refresh
    ORA-12015:cannot create a fast refresh materialized view from a complex query
    create materialized view MV_DGN_TEST_SESSION                                                            
    refresh start with trunc(sysdate)+4/24                                                                  
    next trunc(sysdate+1)+4/24                                                                              
    as                                                                                                      
    WITH    bad_domain_groups as                                                                            
        SELECT DISTINCT tsd.domain_group_id                                                                 
           FROM test_session_detail tsd,                                                                    
          test_session ts             ,                                                                     
          test_detail td                                                                                    
          WHERE tsd.test_session_id     = ts.test_session_id                                                
        AND tsd.test_detail_id          =td.test_detail_id                                                  
        AND ts.test_session_status_id  = 4                                                                  
        AND td.test_type_id            =8                                                                   
        AND tsd.test_session_status_id <>  3                                                                
        AND tsd.domain_group_id IS NOT NULL                                                                 
    select a.test_session_id,b.test_session_detail_id,b.test_detail_id,a.completion_date,a.institution_id,  
    b.score,b.domain_group_id                                                                               
       FROM test_session a ,                                                                                
        test_session_detail b,                                                                              
        test_detail c                                                                                       
        , bad_domain_groups    bad                                                                          
        WHERE a.test_session_id     =b.test_session_id                                                      
      AND a.test_session_status_id IN (3,4)                                                                 
      AND b.test_detail_id          =c.test_detail_id                                                       
      AND c.test_type_id             IN (8)                                                                 
      AND b.domain_group_id     = bad.domain_group_id (+)                                                   
      AND bad.domain_group_id    IS NULL                                                                    
      AND b.domain_group_id is not null;                                                                     Edited by: user575115 on Nov 18, 2009 11:17 PM

    Docs say:
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_6002.htm#i2106785 :
    "Restrictions on the Defining Query of a Materialized View The materialized view query is subject to the following restrictions:
    * The defining query of a materialized view can select from tables, views, or materialized views owned by the user SYS, but you cannot enable QUERY REWRITE on such a materialized view.
    * You cannot define a materialized view with a subquery in the select list of the defining query. You can, however, include subqueries elsewhere in the defining query, such as in the WHERE clause.
    * Materialized join views and materialized aggregate views with a GROUP BY clause cannot select from an index-organized table.
    * Materialized views cannot contain columns of datatype LONG.
    * You cannot create a materialized view log on a temporary table. Therefore, if the defining query references a temporary table, then this materialized view will not be eligible for FAST refresh, nor can you specify the QUERY REWRITE clause in this statement.
    * If the FROM clause of the defining query references another materialized view, then you must always refresh the materialized view referenced in the defining query before refreshing the materialized view you are creating in this statement.
    If you are creating a materialized view enabled for query rewrite, then:
    * The defining query cannot contain, either directly or through a view, references to ROWNUM, USER, SYSDATE, remote tables, sequences, or PL/SQL functions that write or read database or package state.
    * Neither the materialized view nor the master tables of the materialized view can be remote.
    If you want the materialized view to be eligible for fast refresh using a materialized view log, then some additional restrictions may apply."
    Try to reconstruct the query without the WITH-clause.

  • Custom Materialized View

    Hi
    I am ha query regarding Materialized View .
    Materialized View Query :
    select * from emp@db1 where salary in ('1000','3000');
    Scenario :
    In the DB2 (Target DB) :
    create materialized view emp_mv
    refresh force on demand
    as
    select * from emp@db1 where salary in ('1000','3000');
    Replication works fine .
    In DB1 (Source DB) :
    Update emp set salary=2000 where salary=1000 and empno=123;
    Now in the DB2 (where my MV is located) , i want the existing record (salary=1000) to be still there and the new record (salary=2000) should not be present for empno=123
    In DB1 (Source DB) :
    Update emp set salary=3000 where salary=2000 and empno=123;
    Now in the DB2 (where my MV is located) , i want the previous record (salary=1000) to be still there and the new record (salary=3000) should also be present for empno=123 (Now there should be tow records)
    Is it possible ?
    Any pointers is appreciated !
    Thanks

    A Materialized View is designed (intended) to give you a copy of data as the data exists in the source. If that row (with the pre-delete image) does not exist in the source, it should not exist in the MV.
    How would you distinguish between the two images of the row at the MV site ? Which one is the "older" one and which is the "newer" one ? You'd have to write custom methods (tags, timestamps etc) to differentiate between the two rows.
    A Materialized View is a generic solution. You cannot customize.
    You have to define your own custom table (with the additional tagging methods) and your own procedures to replicate the two images of the same row. That is one of the uses of triggers. Before the row is updated, copy the preupdate image of the row (with additional column(s) for tagging the change) out to another table.
    The "custom" MV can then be defined as a UNION of the two tables, the "master" table and the "audit trail" table.
    You'll have to consider how you will handle DELETEs as well.
    Hemant K Chitale

Maybe you are looking for

  • Can't pass event from WebDynPro to JspDynPage - why?

    I Created JSP project and embedded in main page script (in its title), which subscribes to event by EPCM API, EPCM.subscribeEvent("urn:ru.intertech.common.wd.component", "save",   go); and created WebDynPro page that fires event using, when pressing

  • How to recover lost items from the fone

    m using N70.I cut all the fotos from my gallery folder via an USB cable and pasted in a folder on my pc. somehow,i deleted the pics from the pc. I tried to search for in the pc in vain. i then tried to use lifeblog.but found out that my fotos from th

  • How to get rid of the Folders which hold the attachements

    Before upgrading to Maverick I had a folder called Mail Attachements where all my attachements went in. When looking for an attachement it was very easy to look for it as I could organise it alphabetically or by date. Now eacht attachement is in a fo

  • FontExplorer X and Pages?

    Hello, I just installed iWork '08. I want to create a flyer template for a client so they don't have to learn Illustrator. I'm using Linotype FontExplorer X to manage my fonts, however, the only fonts listed in Pages are the System fonts. Without sen

  • How to make a photo slideshow

    when i try to make a slide show from my photos in iphoto it will not work. i get a gray box with a question mark in the middle of the screen all my photos are on the top but i can not go any further i have tried everything.