如何解决视图物化值重复并添加空值
晚上好,
我有一个正确创建的物化视图,但每次更新表时我都会复制记录:“tabla_hija”。
测试:
-如果我更新表“detalle orden”,则更新成功。记录不重复。
-如果我更新表“tabla_hija”,rowids 会重复并且它们显示为空。如果更新“tabla_hija”,我该如何做,它不会产生这些错误。
obs:“tabla_hija”具有该结构,我无法更改它,它不与主键关联,如果不是与名为“vvalor”的字段关联
目前的结构和内容
CREATE MATERIALIZED VIEW LOG ON detalle_ordenes
WITH ROWID
INCLUDING NEW VALUES;
CREATE MATERIALIZED VIEW LOG ON tabla_hija
WITH ROWID
INCLUDING NEW VALUES;
create materialized view vm_prueba2
refresh fast on demand
with rowid
as
select
o.rowid o_rowid,c.rowid c_rowid,e.rowid e_rowid,ordenid,o.detalleid,o.productoid,nvl(c.vdescricion,'') as ddesc,e.vdescricion
from detalle_ordenes o,tabla_hija c,tabla_hija e
where
( o.estado=c.vvalor(+) and c.tipo_filtro=1 or c.vvalor is null ) and
( o.segmento=e.vvalor(+) and e.tipo_filtro=2 or e.vvalor is null );
exec DBMS_MVIEW.REFRESH('vm_prueba2');
解决方法
我认为它是重复的,因为如果 vvalor 列在两种情况下都为空,它将从 c 别名和 e 别名中检索两行,我建议删除 (vvalor is null) 条件,因为您已经使用左外连接将其与 detalle_ordenes 表中的 estado 和 segmento +),或重新排列括号以仅包含两个“或”边条件,例如:
( o.estado=c.vvalor(+) and (c.tipo_filtro=1 or c.vvalor is null)) and
( o.segmento=e.vvalor(+) and (e.tipo_filtro=2 or e.vvalor is null));
祝你好运。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。