我最近从Oracle 10g迁移到Oracle 12c,当我尝试创建物化视图时,我收到此错误
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上,Materialized视图工作正常,但是如果我执行相同的SQL指令在Oracle 12c上我得到了错误。
这是我用来创建物化视图的SQL指令
create materialized view vm_xxx as
SELECT
id,
Internal_function(id) Internal_value
FROM tableA
这是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;
怎么能告诉我怎么办才能解决这个问题? o建议我创建这个物化视图的替代方案
答案 0 :(得分: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;