【发布时间】:2011-11-20 17:23:01
【问题描述】:
当我在 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替换为普通表并手动删除和刷新数据。这种方法行得通,但似乎有点 hack。
或者(也许最好)我只想看一个示例,其中可以有两个表,并将它们加入一个物化视图,其中一个基表是批量更新的(并且不需要反映在物化视图),但其他更新应反映在物化视图中(即它是“一半”fast refresh on commit 和一半complete refresh on demand)。我尝试使用refresh force,但是当使用EXECUTE DBMS_MVIEW.EXPLAIN_MVIEW() 时,我发现没有证据表明提交时刷新刷新可用。我也想用union alls 来做这件事。
【问题讨论】:
-
+1 更好地解释,现在说明:)
-
test3没有多大意义:select null from dual where 0 = 1永远不会返回一行。 -
@Allan:这是一种将其整合为聚合的技巧。如果它停止错误,请随意删除它。
-
@Clinton:只是为了清楚起见:在数据库术语中,复合查询具有
union语句(或任何其他集合运算符);聚合查询有一个group by子句。在这里没有太大区别,但它可能会使 Oracle 文档更有意义。
标签: sql database oracle materialized-views