我有一个View,想要通过DB Link插入。但它给出了错误“ORA-02070:数据库在此上下文中不支持”。我该如何解决这个错误?
CREATE OR REPLACE FORCE VIEW V_TEST
(
OBJECT_ID,
SEQUENCE,
SCHEMA_NAME,
OBJECT_NAME,
OBJECT_TYPE_NAME,
LINE,
POSITION,
ERROR_MESSAGE,
CREATE_DATE
)
AS
SELECT dbaObjects.OBJECT_ID,
dbaErrors.SEQUENCE,
dbaErrors.OWNER AS SCHEMA_NAME,
dbaErrors.NAME AS OBJECT_NAME,
dbaErrors.TYPE AS OBJECT_TYPE_NAME,
dbaErrors.LINE,
dbaErrors.POSITION,
dbaErrors.TEXT AS ERROR_MESSAGE,
SYSDATE AS CREATE_DATE
FROM SYS.DBA_OBJECTS dbaObjects, SYS.DBA_ERRORS dbaErrors
WHERE dbaObjects.OWNER = dbaErrors.OWNER
AND dbaObjects.OBJECT_NAME = dbaErrors.NAME
AND dbaObjects.OBJECT_TYPE = dbaErrors.TYPE
AND dbaObjects.OWNER != 'SYS'
AND dbaObjects.OWNER = 'HELLO'
AND dbaObjects.STATUS = 'INVALID'
AND dbaErrors.TEXT != 'PL/SQL: SQL Statement ignored'
AND dbaErrors.TEXT != 'PL/SQL: Statement ignored'
ORDER BY dbaErrors.OWNER,
dbaErrors.NAME,
dbaErrors.TYPE,
dbaErrors.SEQUENCE;
查看和远程表类型相同
插入声明:
INSERT INTO HELLO.T_INVALID_OBJECT_2@VADA (OBJECT_ID,
SEQUENCE,
SCHEMA_NAME,
OBJECT_TYPE_NAME,
OBJECT_NAME,
LINE,
POSITION,
ERROR_MESSAGE,
CREATE_DATE)
SELECT V.OBJECT_ID,
V.SEQUENCE,
V.SCHEMA_NAME,
V.OBJECT_TYPE_NAME,
V.OBJECT_NAME,
V.LINE,
V.POSITION,
V.ERROR_MESSAGE,
V.CREATE_DATE
FROM V_TEST V;
给出错误插入声明:(
答案 0 :(得分:0)
问题与视图中使用的视图(DBA_SOURCES
和DBA_ERRORS
)有某种关系。请参阅与V$SESSION
here和here相同变体的讨论。
不幸的是,我没有看到与V $ SESSION相同的简单解决方案(如上面链接中所提出的),在我看来问题是由于sys_context
的调用引起的(视图DBA_OBJECTS
的嵌套视图。所以 propper 解决方案是编写您自己的DBA_OBJECTS
版本而不使用sys_context
/ USERENV
或创建此数据的本地副本(例如在GTT中) )
无论如何,有两种解决方法:
1)还原插入,即通过DB LINK从视图连接到远程数据库插件。
insert into t_demo
select * from v_demo@demo;
如果无法连接远程数据库,您可以
2)或者在远程数据库上定义一个程序并从本地数据库中调用它
-- ON REMOTE DB
create procedure ins_remote
AS
BEGIN
insert into t_demo
select * from v_demo@demo;
END;
/
-- plus grants for execute
-- ON LOCAL DB
begin
ins_remote@demo;
end;
/