2011-09-20 48 views
12

当我上运行的Oracle 10g以下代码:甲骨文物化视图错误:代码中包含了

SQL Error: ORA-12053: this is not a valid nested materialized view 
12053. 00000 - "this is not a valid nested materialized view" 
*Cause: The list of objects in the FROM clause of the definition of this 
      materialized view had some dependencies upon each other. 
*Action: Refer to the documentation to see which types of nesting are valid. 

我不”:

drop materialized view test4; 
drop materialized view test3; 
drop table test2; 
drop table test1; 

create table test1 
(
    x1 varchar2(1000), 
    constraint test1_pk primary key (x1) 
); 

create materialized view log on test1 with sequence; 

create table test2 
(
    x2 varchar2(1000), 
    constraint test2_pk primary key (x2) 
); 

create materialized view log on test2 with sequence; 

create materialized view test3 
refresh complete on demand 
as 
(
    select x1 from test1 
    union all 
    select null from dual where 0 = 1 
); 

alter table test3 add constraint test3_pk primary key (x1); 

create materialized view log on test3 with sequence; 

create materialized view test4 
refresh fast on commit 
as 
(
    select t1.rowid as rid1, t2.rowid as rid2, t1.x1 u1, t2.x2 
    from test3 t1, test2 t2 
    where t1.x1 = t2.x2 
); 

我在试图创建物化视图test4得到这个错误了解“FROM子句”中的任何对象如何相互依赖。

我如何得到这个工作?目前我能想到的唯一工作是用普通表替换test3并手动删除和刷新数据。这种方法很有效,但似乎有点破解。

或者(也许最好)我只想看一个可以有两个表的例子,并将它们连接到一个物化视图中,其中一个基表被批量更新(并且不需要反映在物化视图中),但其他更新应反映在物化视图中(即它是“一半”fast refresh on commit,和一半complete refresh on demand)。我尝试使用refresh force,但是当使用EXECUTE DBMS_MVIEW.EXPLAIN_MVIEW()时,我发现没有可用的提交刷新刷新的证据。我也想用union all来做到这一点。

+0

+1更好的解释和现在ilustrated :) –

+0

'test3'没有太大的意义:'从0选择零对0 = 1'将永远不会返回一行。 – Allan

+0

@Allan:这是一个黑客,使其成为一个聚合。如果它停止了错误,请随时删除它。 – Clinton

回答

2

Oracle

Restrictions for Using Multitier Materialized Views

Both master materialized views and materialized views based on materialized views must:

  • Be primary key materialized views
  • Reside in a database that is at 9.0.1 or higher compatibility level

Note: The COMPATIBLE initialization parameter controls a database's compatibility level.

但是报价,我会尽力为你解决。我会回来的。

更新:对不起,我没有成功。你有太多的限制:)

+0

“太多限制”?你什么意思?我的限制是什么? – Clinton

+0

复杂的MV(所有工会),一个“批量刷新”(刷新完成)... –

0

你可能是出于运气,每个Oracle文档:

http://download.oracle.com/docs/cd/B28359_01/server.111/b28313/basicmv.htm#i1006734

You can create a nested materialized view on materialized views, but all parent and base materialized views must contain joins or aggregates. If the defining queries for a materialized view do not contain joins or aggregates, it cannot be nested. All the underlying objects (materialized views or tables) on which the materialized view is defined must have a materialized view log. All the underlying objects are treated as if they were tables. In addition, you can use all the existing options for materialized views.

3

可以使TEST4物化视图刷新快是这样的:

SQL> create table test1 
    2 (x1 varchar2(1000) 
    3 , constraint test1_pk primary key (x1) 
    4 ) 
    5/

Table created. 

SQL> create materialized view log on test1 with rowid 
    2/

Materialized view log created. 

SQL> create table test2 
    2 (x2 varchar2(1000) 
    3 , constraint test2_pk primary key (x2) 
    4 ) 
    5/

Table created. 

SQL> create materialized view log on test2 with rowid 
    2/

Materialized view log created. 

SQL> create materialized view test4 
    2 refresh fast on commit 
    3 as 
    4 select t1.rowid as rid1 
    5   , t2.rowid as rid2 
    6   , t1.x1 u1 
    7   , t2.x2 
    8  from test1 t1 
    9   , test2 t2 
10  where t1.x1 = t2.x2 
11/

Materialized view created. 

SQL> insert into test1 values ('hello') 
    2/

1 row created. 

SQL> insert into test2 values ('hello') 
    2/

1 row created. 

SQL> commit 
    2/

Commit complete. 

SQL> select * from test4 
    2/

RID1    RID2 
------------------ ------------------ 
U1 
--------------------------------------------- 
X2 
--------------------------------------------- 
AAATU5AAEAAAssfAAA AAATU8AAEAAAssvAAA 
hello 
hello 


1 row selected. 

您的情况不适用,因为对于嵌套的MV工作,底层MV不能是基本的MV。这听起来很奇怪,但你需要像test3那样的技巧来使它工作。另外,要使联合MV工作,需要使用ROWID创建基础表的物化视图日志。

您可能想看看我写的关于快速刷新物化视图错误的一系列博文。他们描述了几乎所有的限制:

Basic MV's
Join MV's
Aggregate MV's
Union all MV's
Nested MV's
MV_CAPABILITIES_TABLE
Summary

问候,
罗布。


添加:29-09-2011

下面是使用UNION ALL招嵌套MV上test2的还有一个例子:

SQL> create table test1 
    2 (x1 varchar2(1000) 
    3 , constraint test1_pk primary key (x1) 
    4 ) 
    5/

Table created. 

SQL> create materialized view log on test1 with rowid 
    2/

Materialized view log created. 

SQL> create table test2 
    2 (x2 varchar2(1000) 
    3 , constraint test2_pk primary key (x2) 
    4 ) 
    5/

Table created. 

SQL> create materialized view log on test2 with rowid 
    2/

Materialized view log created. 

SQL> create materialized view test2_mv 
    2 refresh fast on commit 
    3 as 
    4 select rowid rid 
    5  , x2 
    6  , 'A' umarker 
    7 from test2 
    8 union all 
    9 select rowid 
10  , x2 
11  , 'B' 
12 from test2 
13 where 1=0 
14/

Materialized view created. 

SQL> alter table test2_mv add constraint test2_mv_pk primary key(x2) 
    2/

Table altered. 

SQL> create materialized view log on test2_mv with rowid 
    2/

Materialized view log created. 

SQL> create materialized view test3 
    2 refresh fast on commit 
    3 as 
    4 select rowid rid 
    5  , x1 
    6  , 'A' umarker 
    7 from test1 
    8 union all 
    9 select rowid 
10  , x1 
11  , 'B' 
12 from test1 
13 where 0 = 1 
14/

Materialized view created. 

SQL> alter table test3 add constraint test3_pk primary key (x1) 
    2/

Table altered. 

SQL> create materialized view log on test3 with rowid 
    2/

Materialized view log created. 

SQL> create materialized view test4 
    2 refresh fast on commit 
    3 as 
    4 select t1.rowid as rid1 
    5   , t2.rowid as rid2 
    6   , t1.x1 u1 
    7   , t2.x2 
    8  from test3 t1 
    9   , test2_mv t2 
10  where t1.x1 = t2.x2 
11/

Materialized view created. 

SQL> insert into test1 values ('hello') 
    2/

1 row created. 

SQL> insert into test2 values ('hello') 
    2/

1 row created. 

SQL> commit 
    2/

Commit complete. 

SQL> select * from test4 
    2/

RID1    RID2 
------------------ ------------------ 
U1 
--------------------------------------------------- 
X2 
--------------------------------------------------- 
AAATXbAAEAAAstdAAA AAATXXAAEAAAstNAAA 
hello 
hello 


1 row selected. 

希望这有助于!

+0

“这听起来很奇怪,但你需要一个像你用test3做的工作,使其工作”: 你的回答只给出了代码,以便在两张表上建立物化视图,我已经可以做到这一点。你可以给我示例代码,这个技巧可以让我在快速刷新视图的基础上完成刷新按需视图? – Clinton

+0

解决方案取决于您的完整刷新视图的样子。它是基本的,连接,聚合,联合还是嵌套MV?在你的例子中,test3 MV是不必要的。 –

+0

或者是你的test3 MV不是为了让它成为一个联盟所有的MV而不是一个基本的MV,我想知道...... –