create materialized view mv_myview refresh fast as
select a.*
from tableA a
where
not exists (select * from tableB b where a.my_id = b.my_id);
3 回答
2
启用快速刷新很棘手,有许多奇怪的限制和无用的错误消息 . 在这种情况下,您需要创建物化视图日志 WITH ROWID ,使用 (+) 连接语法,并为每个表添加 ROWID .
create table tablea(my_id number primary key, a number);
create table tableb(my_id number primary key, b number);
create materialized view log on tablea with rowid;
create materialized view log on tableb with rowid;
create materialized view mv_myview refresh fast on commit as
select a.my_id, a.a, b.b, a.rowid a_rowid, b.rowid b_rowid
from tableA a, tableB b
where a.my_id = b.my_id(+)
and b.My_id IS NULL;
insert into tablea values(1, 1);
commit;
select * from mv_myview;
MY_ID A B A_ROWID B_ROWID
----- - - ------- -------
1 1 AAAUH3AAEAAC+t0AAA
3
在oracle 11下执行查询,我遇到以下错误:
使用LEFT JOIN,我遇到了同样的问题:
create materialized view mv_myview refresh fast as
select a.*
from tableA a LEFT JOIN tableB b ON a.my_id = b.my_id
where
b.id IS NULL;
使用NOT IN的同样问题......
create materialized view mv_myview refresh fast as
select a.*
from tableA a
where
a.my_id not in (select b.my_id from tableB b);
3 回答
启用快速刷新很棘手,有许多奇怪的限制和无用的错误消息 . 在这种情况下,您需要创建物化视图日志
WITH ROWID
,使用(+)
连接语法,并为每个表添加ROWID
.在oracle 11下执行查询,我遇到以下错误:
使用LEFT JOIN,我遇到了同样的问题:
使用NOT IN的同样问题......
急救信息非常清楚:
这个问题似乎不可能 . 您必须更改视图类型 .
我想不出一个完整的解决方法 . 如果由于某些原因导致的不存在的反连接效率低下,那么您可以基于优化创建快速刷新MV:
反连接通常非常有效 . 你不只是错过了索引吗?