Why does a ORA-12054 error occur when creating this simple materialized view example?

前端 未结 3 1036
既然无缘
既然无缘 2021-01-06 19:06
ALTER TABLE RECORDINGS ADD PRIMARY KEY (ID);

CREATE MATERIALIZED VIEW LOG ON RECORDINGS TABLESPACE USERS NOLOGGING;

DROP MATERIALIZED VIEW REC_SEARCH_TEST;
CREATE          


        
3条回答
  •  天命终不由人
    2021-01-06 19:14

    "Perhaps the example isn't the best, because I want to expand the view to a more complicated query that will require a distinct keyword, right now I am just trying to get it working on a basic level. "

    The DISTINCT is the cause of the ORA-12054.

    SQL> CREATE MATERIALIZED VIEW REC_SEARCH_TEST
        REFRESH COMPLETE ON COMMIT
        AS (
           SELECT DISTINCT empno, ename FROM emp
       )
    /
      2    3    4    5    6  
           SELECT DISTINCT empno, ename FROM emp
                                             *
    ERROR at line 4:
    ORA-12054: cannot set the ON COMMIT refresh attribute for the materialized view
    
    
    Elapsed: 00:00:01.14
    SQL> SQL> 
    SQL> CREATE MATERIALIZED VIEW REC_SEARCH_TEST
        REFRESH COMPLETE ON COMMIT
        AS (
           SELECT empno, ename FROM emp
       )
    /
      2    3    4    5    6  
    Materialized view created.
    
    Elapsed: 00:00:02.33
    SQL> 
    

    Why not start with a something that works? Remove the DISTINCT. Get your MView working. Then complicate it later when it becomes necessary.

    Although, as you already know you cannot use a DISTINCT you will have to revise either your query's logic or your refresh strategy.

提交回复
热议问题