gpt4 book ai didi

oracle - 在 Oracle 中创建包含部分主键的物化 View 时无法设置 ON COMMIT 刷新属性

转载 作者:行者123 更新时间:2023-12-04 02:16:53 28 4
gpt4 key购买 nike

我需要将作为主键一部分的列的唯一值从表中提取到物化 View 中。如果使用“刷新完成”,我可以创建物化 View ,但在尝试使用“提交时快速刷新”时没有运气。任何人都可以指出我是否遗漏了什么或 Oracle 不支持此类操作。

示例输出如下所示。谢谢。

SQL> create table TEST( col1 number, col2 number, col3 varchar(32), CONSTRAINT test_pk Primary Key (col1, col2));

Table created.

SQL> create materialized view test_mv build immediate refresh fast on commit as select distinct col2 from test;
create materialized view test_mv build immediate refresh fast on commit as select distinct col2 from test
*
ERROR at line 1:
ORA-12054: cannot set the ON COMMIT refresh attribute for the materialized view


SQL> create materialized view test_mv build immediate refresh complete as select distinct col2 from test;

Materialized view created.

SQL> drop materialized view test_mv;

Materialized view dropped.

SQL> create materialized view log on test;

Materialized view log created.

SQL> create materialized view test_mv build immediate refresh fast on commit as select distinct col2 from test;
create materialized view test_mv build immediate refresh fast on commit as select distinct col2 from test
*
ERROR at line 1:
ORA-12054: cannot set the ON COMMIT refresh attribute for the materialized view

最佳答案

您的观点的主要问题是 DISTINCT 子句。提交时快速刷新对底层查询非常敏感。物化 View 必须满足许多规则才能支持快速刷新。 DISTINCT 阻止它。

您可以使用 DBMS_MVIEW.EXPLAIN_MVIEW 过程检查物化 View 的功能:

DECLARE
result SYS.EXPLAINMVARRAYTYPE := SYS.EXPLAINMVARRAYTYPE();
BEGIN
DBMS_MVIEW.EXPLAIN_MVIEW('TEST_MV', result);

FOR i IN result.FIRST..result.LAST LOOP
DBMS_OUTPUT.PUT_LINE(result(i).CAPABILITY_NAME || ': ' || CASE WHEN result(i).POSSIBLE = 'T' THEN 'Yes' ELSE 'No' || CASE WHEN result(i).RELATED_TEXT IS NOT NULL THEN ' because of ' || result(i).RELATED_TEXT END || '; ' || result(i).MSGTXT END);
END LOOP;
END;

您可以在文档中找到更多信息 http://docs.oracle.com/cd/B28359_01/server.111/b28313/basicmv.htm#i1007007

关于oracle - 在 Oracle 中创建包含部分主键的物化 View 时无法设置 ON COMMIT 刷新属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33293083/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com