ORA:12054使用UNION ALL创建物化视图

时间:2013-07-28 19:21:39

标签: oracle exception materialized-views union-all

当我做这个动作时,我似乎得到了ORA:12054。我真的很感激一些帮助。 谢谢

create table daniel (id number, name varchar2(40));
alter table daniel add constraint daniel_pk primary key(id);
create materialized view log on daniel with rowid;

create materialized view mv_test
refresh fast on commit as
select id, name, rowid rid
from daniel
UNION ALL
select id, name, rowid rid
from daniel;

物化的创造抛出了ORA。

谢谢!

1 个答案:

答案 0 :(得分:1)

由于UNION ALL,Oracle推出了ORA-12054例外。它不喜欢重复。删除ALL关键字,你有一个有效的MView,但也是一个令人厌倦的:你也可以完全删除第二个查询,因为你无论如何都不会有重复。

当然,MView查询的虚假性质可能只是您简化测试用例以便在SO上发布的方式的人工制品。如果是这样,如果你提出了一个更现实的方案,它将有助于我们了解你的情况。

请注意,虽然删除ALL会为您提供有效的MView,但您仍然无法创建它。您的MView日志仅指定ROWID,这意味着您无法使用REFRESH FAST选项创建MView。您可以选择REFRESH FULL或者您需要在Log规范中包含主键:

SQL> create materialized view mv_test
refresh fast on commit as
select id, name, rowid rid
from daniel  2    3    4  
  5  /
from daniel
     *
ERROR at line 4:
ORA-23415: materialized view log for "APC"."DANIEL" does not record the primary key


SQL> drop materialized view log on daniel ;

Materialized view dropped.

SQL> create materialized view log on daniel with rowid, primary key;

Materialized view log created.

SQL> create materialized view mv_test
refresh fast on commit as
select id, name, rowid rid
from daniel  2    3    4  
  5  /

Materialized view created.

SQL>