Oracle 10.2中这种快速刷新的视图定义有什么问题:
create table A
(
ID number(19,0) not null constraint A_PK primary key using index
, C number(9,0) not null
);
create table B
(
ID number(19,0) not null constraint B_PK primary key using index
, A_ID number(19,0) not null constraint A_FK references A(ID) on delete cascade
, D number(9,0) not null
);
create index B_FK_IDX on B(A_ID);
create materialized view log on A
with primary key, rowid, sequence (C) including new values;
create materialized view log on B
with primary key, rowid, sequence (A_ID, D) including new values;
create materialized
view X
refresh fast with primary key
as
select A.ID as A_ID
, A.ROWID as A_ROWID
, B.ID as B_ID
, B.ROWID as B_ROWID
, A.C
, B.D
from A
inner join
B
on B.A_ID = A.ID;
当脚本执行时,我得到:
table A created.
table B created.
index B_FK_IDX created.
materialized view LOG created.
materialized view LOG created.
...[view definition and local error message left out]
SQL-Error: ORA-12015: cannot create a fast refresh materialized view from a complex query
12015. 00000 - "cannot create a fast refresh materialized view from a complex query"
*Cause: Neither ROWIDs and nor primary key constraints are supported for
complex queries.
*Action: Reissue the command with the REFRESH FORCE or REFRESH COMPLETE
option or create a simple materialized view.
我无法看到违反Oracle支持文档179466.1中定义的物化视图的任何限制。
答案 0 :(得分:6)
您不能使用ANSI连接语法,请使用旧的Oracle连接语法。这是Oracle中的一个错误。 很久以前我为此开了个案,但Oracle认为这只是缺少文档!
答案 1 :(得分:2)
来自docs:
仅使用联接的物化视图上的快速刷新限制
仅使用联接定义实体化视图的查询,并且没有聚合对快速刷新具有以下限制:
"快速刷新的一般限制"。
的所有限制他们不能拥有GROUP BY子句或聚合。
FROM列表中所有表的Rowid必须出现在查询的SELECT列表中。
物化视图日志必须与查询的FROM列表中的所有基表的rowid一起存在。