Home » SQL & PL/SQL » SQL & PL/SQL » Cannot refresh Materialized View with Join in Oracle 12c 12.1.0.1.0 after Create (Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production, Windows Server 2012)
Cannot refresh Materialized View with Join in Oracle 12c 12.1.0.1.0 after Create [message #612784] Thu, 24 April 2014 14:14 Go to next message
appsystems
Messages: 6
Registered: April 2014
Junior Member
Hello,
last week i migrated from Oracle 10g to 12c, but i had problems with Refreshing Materialized views, which contain joins.

Then i tried an example on 12c and i got still the same mistake.

i have installed a clean Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production, i created 2 testtables like this:

CREATE TABLE Y_FIRST ( ID NUMBER NOT NULL PRIMARY KEY, TEXT VARCHAR2(10 BYTE), ID_FOREIGN NUMBER NOT NULL );
CREATE TABLE Y_SECOND ( ID NUMBER NOT NULL PRIMARY KEY, TEXT2 VARCHAR2(10 BYTE));


Then i inserted some Sample Statements into it, like this:
Insert into Y_FIRST (ID, TEXT, ID_FOREIGN) Values (1, 'erst1', 1);
Insert into Y_FIRST (ID, TEXT, ID_FOREIGN) Values (2, 'erst2', 1);
Insert into Y_FIRST (ID,  TEXT, ID_FOREIGN) Values (3, 'erst3', 2);
Insert into Y_FIRST  (ID,  TEXT, ID_FOREIGN) Values (4, 'erst4', 2);
COMMIT;

Insert into Y_SECOND (ID, TEXT2) Values (1, 'yes');
Insert into Y_SECOND (ID, TEXT2) Values (2, 'no');
COMMIT;


Afterwards i created a Materialised View like this:
CREATE MATERIALIZED VIEW MV (RON,ID1,NAME1,ID2,NAME2) REFRESH COMPLETE ON DEMAND WITH PRIMARY KEY AS
SELECT ROWNUM AS RON, ab.ID AS ID1, ab.text AS NAME1,b.ID AS ID2, b.text2 AS NAME2 FROM y_first ab, y_second b WHERE ab.id_foreign = b.id;
COMMIT;


this worked so far, but when i tried to refresh the Materialized View with the command
EXEC DBMS_MVIEW.REFRESH('mv','?');    

or
EXEC DBMS_MVIEW.REFRESH('mv','F');


i get the following exception
ORA-12008: error in materialized view refresh path
ORA-01732: data manipulation operation not legal on this view materialized view
ORA-06512: in "SYS.DBMS_SNAPSHOT", line 2802
ORA-06512: in "SYS.DBMS_SNAPSHOT", line 3039
ORA-06512: in "SYS.DBMS_SNAPSHOT", line 2998
ORA-06512: in line 1


The same code works in Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production, but for 12c i had no success.

I also tried to set some materialized view Logs on 12c with:
CREATE MATERIALIZED VIEW LOG ON Y_FIRST with primary key, rowid, sequence including new values;
CREATE MATERIALIZED VIEW LOG ON Y_SECOND with primary key, rowid, sequence including new values;


but i still had no success with it.

Do you have any idea, what the solution to this problem could be?

Thank you for your help!
Kind regards,

Edvin

[Updated on: Thu, 24 April 2014 14:16]

Report message to a moderator

Re: Cannot refresh Materialized View with Join in Oracle 12c 12.1.0.1.0 after Create [message #612786 is a reply to message #612784] Thu, 24 April 2014 14:28 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
Is it PDB or non-CDB? I have no issues with non-CDB:

SCOTT@sol12 > select banner from v$version
  2  /

BANNER
--------------------------------------------------------------------------------
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
PL/SQL Release 12.1.0.1.0 - Production
CORE    12.1.0.1.0      Production
TNS for 64-bit Windows: Version 12.1.0.1.0 - Production
NLSRTL Version 12.1.0.1.0 - Production

SCOTT@sol12 > EXEC DBMS_MVIEW.REFRESH('mv','C');

PL/SQL procedure successfully completed.

SCOTT@sol12 > EXEC DBMS_MVIEW.REFRESH('mv','F');
BEGIN DBMS_MVIEW.REFRESH('mv','F'); END;

*
ERROR at line 1:
ORA-12004: REFRESH FAST cannot be used for materialized view "SCOTT"."MV"
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 2802
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 3039
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 2998
ORA-06512: at line 1


SCOTT@sol12 > EXEC DBMS_MVIEW.REFRESH('mv','?');

PL/SQL procedure successfully completed.

SCOTT@sol12 > 


Have no time now to test it on PDB.

SY.
Re: Cannot refresh Materialized View with Join in Oracle 12c 12.1.0.1.0 after Create [message #612787 is a reply to message #612786] Thu, 24 April 2014 14:48 Go to previous messageGo to next message
appsystems
Messages: 6
Registered: April 2014
Junior Member
Hey, thank you for your fast reply!

This is my version:
select banner from v$version;

Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
PL/SQL Release 12.1.0.1.0 - Production
CORE	12.1.0.1.0	Production
TNS for 64-bit Windows: Version 12.1.0.1.0 - Production
NLSRTL Version 12.1.0.1.0 - Production


I didn't choose any Container at the Installation (i deactivated it), so i guess it's a non-cdb?

is there any Select-Statement to check this, so we can go sure that this isn't that problem?

i only got this select-statement:
select * from v$parameter where name like 'noncdb%';

NUM,NAME,TYPE,VALUE,DISPLAY_VALUE,ISDEFAULT,ISSES_MODIFIABLE,ISSYS_MODIFIABLE,ISPDB_MODIFIABLE,ISINSTANCE_MODIFIABLE,ISMODIFIED,ISADJUSTED,ISDEPRECATED,ISBASIC,DESCRIPTION,UPDATE_COMMENT,HASH,CON_ID
3317,noncdb_compatible,1,FALSE,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,Non-CDB Compatible,null,2594626030,0



i hope that it's readable, maybe let's do a smaller select:

select NAME, DISPLAY_VALUE,ISDEFAULT, ISSES_MODIFIABLE, ISMODIFIED, ISADJUSTED,ISBASIC, DESCRIPTION from v$parameter where name like 'noncdb%'

NAME,DISPLAY_VALUE,ISDEFAULT,ISSES_MODIFIABLE,ISMODIFIED,ISADJUSTED,ISBASIC,DESCRIPTION
noncdb_compatible,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,Non-CDB Compatible




Thank you for your Help!

Any ideas?

Kind regards,
Edvin


Re: Cannot refresh Materialized View with Join in Oracle 12c 12.1.0.1.0 after Create [message #612789 is a reply to message #612787] Thu, 24 April 2014 15:08 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
You issue

select cdb from v$database;

to check if it is container database (CDB) or non-CDB.

SY.
Re: Cannot refresh Materialized View with Join in Oracle 12c 12.1.0.1.0 after Create [message #612790 is a reply to message #612784] Thu, 24 April 2014 15:11 Go to previous messageGo to next message
Michel Cadot
Messages: 68647
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

I doubt a MVIEW defined with ROWNUM is fast refreshable.

[Updated on: Fri, 25 April 2014 00:58]

Report message to a moderator

Re: Cannot refresh Materialized View with Join in Oracle 12c 12.1.0.1.0 after Create [message #612791 is a reply to message #612789] Thu, 24 April 2014 15:26 Go to previous messageGo to next message
appsystems
Messages: 6
Registered: April 2014
Junior Member
Solomon Yakobson wrote on Thu, 24 April 2014 15:08
You issue
select cdb from v$database;
to check if it is container database (CDB) or non-CDB.
SY.


Thank you for your reply!

This is the Result:
select cdb from v$database;

CDB
NO


@Michel Cadot: yeah, i guess so, but i wanted to try if i could set some kind of primary key on it, i was just playing around.
But a complete refresh would be already very nice Smile

Thanks for your feedback,
Do you have any idea how to fix this? I would appreciate that really much.

Kind regards,
Edvin

[Updated on: Thu, 24 April 2014 15:27]

Report message to a moderator

Re: Cannot refresh Materialized View with Join in Oracle 12c 12.1.0.1.0 after Create [message #612792 is a reply to message #612791] Thu, 24 April 2014 15:39 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
I already showed you - complete refresh works fine on my 12C. In any case check what dbms_mview.explain_mview says.

SY.

[Updated on: Thu, 24 April 2014 15:40]

Report message to a moderator

Re: Cannot refresh Materialized View with Join in Oracle 12c 12.1.0.1.0 after Create [message #612794 is a reply to message #612792] Thu, 24 April 2014 16:04 Go to previous messageGo to next message
appsystems
Messages: 6
Registered: April 2014
Junior Member
Solomon Yakobson wrote on Thu, 24 April 2014 15:39
I already showed you - complete refresh works fine on my 12C. In any case check what dbms_mview.explain_mview says.

SY.


Thank you for your reply - i appreciate that very much!
The problem is, that in my Database the same exact constelltion does not work, so i don't have a working solution Confused

I tried the mv_capabilites_table, i uploaded the results as an attachment (The comments are on German, but i hope this shouldn't be a problem - otherwise i will upload later on i translated version of that file)

Thank you for your help.
Can you tell me, what the File means?

Kind regards,
Edvin

[Updated on: Thu, 24 April 2014 16:07]

Report message to a moderator

Re: Cannot refresh Materialized View with Join in Oracle 12c 12.1.0.1.0 after Create [message #612797 is a reply to message #612794] Thu, 24 April 2014 17:58 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
According to the attachment capability REFRESH_COMPLETE has POSSIBLE = Y, so complete refresh should work.
Please post SQL*Plus snippet showing execution of create MV and refresh attempt.

SY.
Re: Cannot refresh Materialized View with Join in Oracle 12c 12.1.0.1.0 after Create [message #612854 is a reply to message #612797] Sat, 26 April 2014 08:13 Go to previous messageGo to next message
appsystems
Messages: 6
Registered: April 2014
Junior Member
Hey, sorry for my late response!

Here is the Screenshot which you wanted to have.
I uploaded it as an attachment.

/forum/fa/11836/0/

if you need any translation, just let me know!

Thank you very much for your help!

Kind regards,
Edvin
Re: Cannot refresh Materialized View with Join in Oracle 12c 12.1.0.1.0 after Create [message #612856 is a reply to message #612854] Sat, 26 April 2014 08:51 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
Sorry, I can't reproduce it in PDB either. What happens when you remove ROWNUM from MV?

SY.
Re: Cannot refresh Materialized View with Join in Oracle 12c 12.1.0.1.0 after Create [message #612858 is a reply to message #612784] Sat, 26 April 2014 09:03 Go to previous messageGo to next message
John Watson
Messages: 8931
Registered: January 2010
Location: Global Village
Senior Member
You cannot fast refresh an MV if you create it as REFRESH COMPLETE, which you did.
Re: Cannot refresh Materialized View with Join in Oracle 12c 12.1.0.1.0 after Create [message #612866 is a reply to message #612854] Sat, 26 April 2014 11:08 Go to previous messageGo to next message
Michel Cadot
Messages: 68647
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
if you need any translation, just let me know!


You can get message in English just executing "set NLS_LANGUAGE=AMERICAN" before starting SQL*Plus.

Re: Cannot refresh Materialized View with Join in Oracle 12c 12.1.0.1.0 after Create [message #612867 is a reply to message #612866] Sat, 26 April 2014 11:43 Go to previous messageGo to next message
9390512774
Messages: 103
Registered: January 2011
Location: hyd
Senior Member
If I want refresh USER_TABLE? how to do it?
Re: Cannot refresh Materialized View with Join in Oracle 12c 12.1.0.1.0 after Create [message #612868 is a reply to message #612867] Sat, 26 April 2014 11:57 Go to previous messageGo to next message
Michel Cadot
Messages: 68647
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

USER_TABLE? You do not refresh USER_TABLES, it is always up to date, it is a view not a materialized view.

Re: Cannot refresh Materialized View with Join in Oracle 12c 12.1.0.1.0 after Create [message #612869 is a reply to message #612868] Sat, 26 April 2014 12:17 Go to previous messageGo to next message
9390512774
Messages: 103
Registered: January 2011
Location: hyd
Senior Member
Thanks for your quick response. I am not able to see the number of rows value as latest row count for each table in NUM_ROWS column in USER_TABLE.
Re: Cannot refresh Materialized View with Join in Oracle 12c 12.1.0.1.0 after Create [message #612870 is a reply to message #612869] Sat, 26 April 2014 12:18 Go to previous messageGo to next message
Michel Cadot
Messages: 68647
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

You have to gather statistics on the table for this.
Catalog views are described in Database Reference.

Re: Cannot refresh Materialized View with Join in Oracle 12c 12.1.0.1.0 after Create [message #612886 is a reply to message #612856] Sat, 26 April 2014 16:40 Go to previous message
appsystems
Messages: 6
Registered: April 2014
Junior Member
Solomon Yakobson wrote on Sat, 26 April 2014 08:51
Sorry, I can't reproduce it in PDB either. What happens when you remove ROWNUM from MV?

SY.


Thank you for your feedback!
I get still the same error after removing the rownum.

i added the screenshot of sqlplus again:

/forum/fa/11844/0/


Do i have to insert some kind of Materialized View log or index to make this work?
because i tried this with one simple table and i get the same mistake, here is the code:

CREATE TABLE Y_TEST2 (
    ID NUMBER NOT NULL PRIMARY KEY,
    TEXT VARCHAR2(255)
 );
 
 insert into y_test2 values(1,'yep');
 insert into y_test2 values(2,'no');
 
CREATE MATERIALIZED VIEW RATSCHINGS.MV_Y_TEST2 (ID,TEXT) REFRESH COMPLETE ON DEMAND WITH PRIMARY KEY AS 
SELECT ID, text FROM Y_TEST2;

exec dbms_mview.refresh('mv_y_test2', 'C');

ORA-12008: error in materialized view refresh path
ORA-01732: data manipulation operation not legal on this view materialized view
ORA-06512: in "SYS.DBMS_SNAPSHOT", line 2802
ORA-06512: in "SYS.DBMS_SNAPSHOT", line 3039
ORA-06512: in "SYS.DBMS_SNAPSHOT", line 2998
ORA-06512: in line 1



and this also didn't work, so i have absolutely no clue, because this should work.

Thank you for your help!
Do you have any clue why this happens with my installation of oracle or any other ideas?


Kind regards,
edvin

[Updated on: Sat, 26 April 2014 17:01]

Report message to a moderator

Previous Topic: how to update hierarchical query
Next Topic: ORA-00942:Table or View does not exist-Store procedure
Goto Forum:
  


Current Time: Fri Apr 26 15:06:54 CDT 2024