简体   繁体   中英

Oracle Materialized View fails ORA-12840 and ORA-06512:

I've recently move from Oracle 10g to Oracle 12c and when I try to create a Materialized View I'm getting this error

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.

I'm confused because on Oracle 10g the Materialized view works fine but if I execute the same SQL instruction On Oracle 12c I get the error.

This is the SQL instructions that I used to create the materialized view

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

And this is the code of Internal_function 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;

How can tell me what could i do to solve this issue? o suggest me alternatives to create this materialized view

Check this out:

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM