Jas*_*son 3 oracle materialized-views primary-key
我需要将作为主键一部分的列的唯一值从表中提取到物化视图中。如果使用“刷新完成”,我可以创建物化视图,但在尝试使用“提交时快速刷新”时却没有运气。谁能指出我是否错过了什么或者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
Run Code Online (Sandbox Code Playgroud)
您的观点的主要问题是 DISTINCT 子句。提交时快速刷新对底层查询非常敏感。物化视图必须满足许多规则才能支持快速刷新。DISTINCT 可以防止这种情况发生。
您可以使用以下过程检查物化视图的功能DBMS_MVIEW.EXPLAIN_MVIEW
:
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;
Run Code Online (Sandbox Code Playgroud)
您可以在文档中找到更多信息http://docs.oracle.com/cd/B28359_01/server.111/b28313/basicmv.htm#i1007007