这个可快速刷新的视图定义有什么问题:它并不复杂和完整,但是引发了 ORA-12015

What's wrong with this fast refreshable view definition: it is not complex and complete, however ORA-12015 is raised

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 中定义的物化视图限制的情况。

来自docs

Restrictions on Fast Refresh on Materialized Views with Joins Only

Defining queries for materialized views with joins only and no aggregates have the following restrictions on fast refresh:

All restrictions from "General Restrictions on Fast Refresh".

They cannot have GROUP BY clauses or aggregates.

Rowids of all the tables in the FROM list must appear in the SELECT list of the query.

Materialized view logs must exist with rowids for all the base tables in the FROM list of the query.

您不能使用 ANSI 连接语法,使用旧的 Oracle 连接语法。这是 Oracle 中的错误。 很久以前我就为此开过一个案例,但是 Oracle 认为这只是缺乏文档!