Home » SQL & PL/SQL » SQL & PL/SQL » ORA-12015: cannot create a fast refresh materialized view from a complex query
ORA-12015: cannot create a fast refresh materialized view from a complex query [message #504823] Wed, 27 April 2011 18:32 Go to next message
masha
Messages: 5
Registered: April 2011
Location: Canada
Junior Member
I'm trying to create materialized view, successfully create logs for all the tables involved.


CREATE MATERIALIZED VIEW LOG ON tbJournal
WITH ROWID, SEQUENCE (tabid, companyid, storelocid, tabstatus, linetype)
INCLUDING NEW VALUES;

CREATE MATERIALIZED VIEW LOG ON TBTABS
WITH ROWID, SEQUENCE (TSTAMP, COMPANYID, NUMGUESTS, POSITIONID, STORELOCID, TABSSTATUS)
INCLUDING NEW VALUES;


CREATE MATERIALIZED VIEW LOG ON TBSTORESHISTORY 
WITH ROWID, SEQUENCE (COMPANYID, ENDDAY, STORELOCID) 
INCLUDING NEW VALUES;
  
CREATE MATERIALIZED VIEW WHGUESTNUM 
BUILD DEFERRED 
REFRESH FAST ON DEMAND 
WITH ROWID USING DEFAULT LOCAL ROLLBACK SEGMENT DISABLE QUERY REWRITE AS
  SELECT T.CompanyId ,
    T.StoreLocid ,
    T.PositionID ,
    TRUNC(T.TStamp - NVL(S.EndDay / 24, 0)) TDate,
    SUM(NumGuests)   AS NumGuests ,
    COUNT(*)         AS NumChecks ,
    COUNT(NumGuests) AS Dummy
  FROM TBStoresHistory S,
    tbTabs T 
  WHERE T.TabsStatus = 2
  AND T.CompanyID    = S.CompanyID
  AND T.StoreLocID   = S.StoreLocID
  AND EXISTS (SELECT 1 FROM tbJournal J
                  WHERE j.tabstatus NOT BETWEEN -6 AND -4 
                  AND j.linetype = 1
                  AND T.tabid = J.tabid
                  AND T.companyid = J.companyid
                  AND T.storelocid = J.storelocid)
  GROUP BY T.Companyid,
    T.StoreLocid ,
    T.PositionID ,
    TRUNC(T.TStamp - NVL(S.EndDay / 24, 0));




The result is ora-12015: cannot create a fast refresh materialized view from a complex query

It does work fine if I remove
AND EXISTS (SELECT 1 FROM tbJournal J
                  WHERE j.tabstatus NOT BETWEEN -6 AND -4 
                  AND j.linetype = 1
                  AND T.tabid = J.tabid
                  AND T.companyid = J.companyid
                  AND T.storelocid = J.storelocid)

from the where clause


Re: ORA-12015: cannot create a fast refresh materialized view from a complex query [message #504824 is a reply to message #504823] Wed, 27 April 2011 18:50 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
We can not change how Oracle behaves so how can we assist you in this situation?
Re: ORA-12015: cannot create a fast refresh materialized view from a complex query [message #504967 is a reply to message #504824] Thu, 28 April 2011 10:21 Go to previous messageGo to next message
masha
Messages: 5
Registered: April 2011
Location: Canada
Junior Member
If you can point out what is wrong in the view, I can rewrite the select. That will be very helpful
Re: ORA-12015: cannot create a fast refresh materialized view from a complex query [message #504968 is a reply to message #504967] Thu, 28 April 2011 10:25 Go to previous messageGo to next message
cookiemonster
Messages: 13966
Registered: September 2008
Location: Rainy Manchester
Senior Member
Surely that's obvious - the exists subquery is what's causing the problem.
Doesn't mean there's a way to rewrite it though.
Re: ORA-12015: cannot create a fast refresh materialized view from a complex query [message #504970 is a reply to message #504967] Thu, 28 April 2011 10:28 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>If you can point out what is wrong in the view, I can rewrite the select. That will be very helpful
submit a Service Request
Re: ORA-12015: cannot create a fast refresh materialized view from a complex query [message #504972 is a reply to message #504968] Thu, 28 April 2011 10:33 Go to previous messageGo to next message
Michel Cadot
Messages: 68757
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
select ... 
from t1
where exists (select null from t2 where t2.X = t1.Y ...)

is equivalent to
select ...
from t1, t2
where  t2.X = t1.Y ...

So try to rewrite in this way.

Regards
Michel
Re: ORA-12015: cannot create a fast refresh materialized view from a complex query [message #504974 is a reply to message #504972] Thu, 28 April 2011 10:39 Go to previous messageGo to next message
masha
Messages: 5
Registered: April 2011
Location: Canada
Junior Member
I wish I could solve it that way, but t1 and t2 have one to many relationship and sum(t1) or count(t1) will give a wrong result.
Re: ORA-12015: cannot create a fast refresh materialized view from a complex query [message #504975 is a reply to message #504972] Thu, 28 April 2011 10:50 Go to previous messageGo to next message
masha
Messages: 5
Registered: April 2011
Location: Canada
Junior Member
If I use distinct the result of the select is correct but on creating the view I get the same error

CREATE MATERIALIZED VIEW WHGUESTNUM 
BUILD DEFERRED 
REFRESH FAST ON DEMAND 
WITH ROWID USING DEFAULT LOCAL ROLLBACK SEGMENT DISABLE QUERY REWRITE AS
  SELECT T.CompanyId ,
    T.StoreLocid ,
    T.PositionID ,
    TRUNC(T.TStamp - NVL(S.EndDay / 24, 0)) TDate,
    SUM(NumGuests)   AS NumGuests ,
    COUNT(*)         AS NumChecks ,
    COUNT(NumGuests) AS Dummy
  FROM TBStoresHistory S,
    tbTabs T, 
    (select distinct tabid,companyid, storelocid  from tbJournal where tabstatus NOT BETWEEN -6 AND -4 AND linetype = 1 ) J
  WHERE T.TabsStatus = 2
  AND T.CompanyID    = S.CompanyID
  AND T.StoreLocID   = S.StoreLocID
                  AND T.tabid = J.tabid
                  AND T.companyid = J.companyid
                  AND T.storelocid = J.storelocid
  GROUP BY T.Companyid,
    T.StoreLocid ,
    T.PositionID ,
    TRUNC(T.TStamp - NVL(S.EndDay / 24, 0));
Re: ORA-12015: cannot create a fast refresh materialized view from a complex query [message #504983 is a reply to message #504975] Thu, 28 April 2011 11:39 Go to previous messageGo to next message
Michel Cadot
Messages: 68757
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Remove the "distinct" and try it (even if it gives the wrong result it is just to see if "distinct" is the reason).

Regards
Michel
Re: ORA-12015: cannot create a fast refresh materialized view from a complex query [message #504987 is a reply to message #504983] Thu, 28 April 2011 11:47 Go to previous messageGo to next message
masha
Messages: 5
Registered: April 2011
Location: Canada
Junior Member
Yes, using distinct is what causing the error.
I also tried unique and select min(..) ... group by, same result
Re: ORA-12015: cannot create a fast refresh materialized view from a complex query [message #504990 is a reply to message #504987] Thu, 28 April 2011 12:06 Go to previous message
Michel Cadot
Messages: 68757
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
So if "distinct" is the root of error try to find why you have several rows, try to add a new condition that will then return only one row.

Regards
Michel
Previous Topic: Return Column name corresponding to values(2 Merged)
Next Topic: Require Months
Goto Forum:
  


Current Time: Fri May 02 11:04:02 CDT 2025