Oracle

物化視圖:compile_error

  • June 11, 2014

在 SCOTT 架構上執行以下程式碼時,我收到了一個編譯錯誤。我在這裡做錯了什麼?我什至沒有告訴我錯誤是什麼。

SQL> create materialized view dept_emp_mv as (  
 2      select dname, job, hiredate, count(*) nbr  
 3                  from emp e  
 4                  join dept d on e.deptno = d.deptno  
 5                  group by dname,hiredate,job);  
Materialized view created.  
SQL>  
SQL> select staleness from user_mviews where lower(mview_name) = 'dept_emp_mv';  
STALENESS  
-------------------  
FRESH  
SQL>  
SQL> insert into emp values (8003, 'TEST', 'TEST', 7902, to_date('20131127','YYYYMMDD'), 2500, null, 20);  
1 row created.  
SQL>  
SQL> commit;  
Commit complete.  
SQL>  
SQL> select staleness from user_mviews where lower(mview_name) = 'dept_emp_mv';  
STALENESS  
-------------------  
NEEDS_COMPILE  
SQL>  
SQL> execute DBMS_SNAPSHOT.REFRESH('DEPT_EMP_MV','C', parallelism => 1);  
PL/SQL procedure successfully completed.  
SQL>  
SQL> select staleness from user_mviews where lower(mview_name) = 'dept_emp_mv';  
STALENESS  
-------------------  
COMPILATION_ERROR  

任何幫助表示讚賞。

更新

在 Oracle 12c 中,這個問題似乎得到了解決。

似乎Oracle在引用時不喜歡物化視圖定義中的ANSI樣式連接……

將定義更改為

create materialized view dept_emp_mv as  
  select dname, job, hiredate, count(*) as nbr  
              from emp e, dept d
              where e.deptno = d.deptno
              group by dname,hiredate,job;

讓它對我有用。

http://sqlfiddle.com/#!4/f706b/1

將 SQL Fiddle 中的定義更改回問題中包含的定義將staleness導致COMPILATION_ERROR.

就個人而言,我會將其歸類為解決方法而不是答案。

引用自:https://dba.stackexchange.com/questions/54129