2016-08-03 236 views
0

最近我已經從Oracle 10g中移動到Oracle 12c和當我嘗試創建一個物化視圖我得到這個錯誤Oracle實體化視圖失敗ORA-12840和ORA-06512:

Error report - 
SQL Error: ORA-12840: cannot access a remote table after parallel/insert direct load txn 
ORA-06512: at "Internal_function", line 11 
12840. 00000 - "cannot access a remote table after parallel/insert direct load txn" 
*Cause: Within a transaction, an attempt was made to perform distributed 
      access after a PDML or insert direct statement had been issued. 
*Action: Commit/rollback the PDML transaction first, and then perform 
      the distributed access, or perform the distributed access before the 
      first PDML statement in the transaction. 

我因爲在Oracle 10g中,物化視圖工作正常,但如果我執行相同的SQL指令,在Oracle 12c上出現錯誤。

這是我用來創建物化視圖

create materialized view vm_xxx as 
SELECT 
     id,  
     Internal_function(id) Internal_value 
FROM tableA 

的SQL指令這是Internal_function函數的代碼

create or replace FUNCTION  "Internal_function" 
(
    v_id in varchar2 
) RETURN VARCHAR2 AS 


total_count number; 
RETURN_VALUE varchar2(1):='N'; 
BEGIN 

    SELECT count(*) 
    INTO total_count 
    FROM 
    tableA e, 
    tableB t 
    WHERE 
    E.id =T.id(+) 
    AND 
    (
    e.v_id1 = v_id 
    OR 
    e.v_id2= v_id 
    OR 
    T.v_id3= v_id); 

    if total_count > 0 then 
     RETURN_VALUE:='Y'; 
    end if; 

    return RETURN_VALUE; 
END Internal_function; 

怎麼能告訴我,我能做些什麼來解決這個問題? Ø建議我的選擇創建此物化視圖

回答

0

檢查了這一點:

create materialized view test_mw as 
SELECT e.id, 
     case 
     when count(*) > 0 then 
      'Y' 
     else 
      'N' 
     end as internal_value 
FROM tableA e, 
     tableB t 
WHERE E.id = T.id(+) 
AND (e.v_id1 = v_id OR e.v_id2 = v_id OR T.v_id3 = v_id) 
group by e.id;