Oracle物化视图错误:包含代码
当我在 Oracle 10g 上运行以下代码时:
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
时出现此错误:
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.
我不明白“FROM 子句”中的任何对象如何相互依赖。
我该如何让它发挥作用?目前我能想到的唯一解决方法是将 test3
替换为普通表并手动删除和刷新数据。这种方法有效,但看起来有点像黑客。
或者(也许最好)我只想看一个示例,其中可以有两个表,并将它们连接到物化视图中,其中一个基表被批量更新(并且不需要反映在物化视图中) ),但其他更新应该反映在物化视图中(即“一半”提交时快速刷新
,一半按需完全刷新
)。我尝试使用刷新力
,但是当使用EXECUTE DBMS_MVIEW.EXPLAIN_MVIEW()
时,我没有发现提交时快速刷新可用的证据。我也想用union all
来做到这一点。
When I run the following code on Oracle 10g:
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
);
I get this error upon trying to create the materialized view test4
:
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.
I don't understand how any of the objects in the "FROM clause" depend on each other.
How do I get this to work? Currently the only work around I can think of is to replace test3
with a ordinary table and manually delete and refresh the data. This approach works, but seems like a bit of a hack.
Alternatively (and perhaps preferably) I'd just like to see an example where can have two tables, and join them into a materialized view, where one of the base tables is bulk updated (and does not need to be reflected in the materialized view) but the others updates should be reflected in the materialized view (i.e. it's kind of "half" fast refresh on commit
, and half complete refresh on demand
). I tried using refresh force
, but when using EXECUTE DBMS_MVIEW.EXPLAIN_MVIEW()
I found no evidence of fash refresh on commit being available. I'd also like to do this with union all
s as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以像这样快速刷新 test4 物化视图:
您的情况不起作用,因为要使嵌套 MV 工作,底层 MV 不能是基本 MV。乍一看这听起来很奇怪,但您需要像使用 test3 那样的技巧才能使其工作。此外,要使连接 MV 正常工作,需要使用 ROWID 创建基础表的物化视图日志。
您可能想查看我撰写的有关快速可刷新物化视图错误的一系列博客文章。它们描述了几乎所有限制:
基本 MV
加入 MV
聚合 MV
合并所有 MV
嵌套 MV
MV_CAPABILITIES_TABLE
摘要
问候,
抢。
Added: 29-09-2011
下面是一个在 test2 上使用 union all 技巧的嵌套 MV 的示例:
希望这会有所帮助!
You can make the test4 materialized view refresh fast like this:
Your case doesn't work because for a nested MV to work, an underlying MV cannot be a basic MV. This sounds strange at first, but you'd need a trick like you did with test3 to make it work. Also, for a join MV to work, the materialized view logs of the underlying table need to be created WITH ROWID.
You might want to look at a series of blog posts I wrote about fast refreshable materialized view errors. They describe almost all restrictions:
Basic MV's
Join MV's
Aggregate MV's
Union all MV's
Nested MV's
MV_CAPABILITIES_TABLE
Summary
Regards,
Rob.
Added: 29-09-2011
Here is an example with a nested MV using the union all trick on test2 as well:
Hope this helps!
引用自 Oracle
不过,我会为你尝试一个解决方案。我会回来的。
更新:抱歉,我没有成功。你的限制太多了:)
Quoting from Oracle
However, I'll try a solution for you. I'll be back.
Update: Sorry I didn't succeded. You have too many restrictions :)
根据 Oracle 文档,您可能不走运:
http://download.oracle.com/docs/cd/B28359_01/server.111/b28313/basicmv.htm#i1006734
You may be out of luck, per the Oracle documentation:
http://download.oracle.com/docs/cd/B28359_01/server.111/b28313/basicmv.htm#i1006734