ORA-02070: database does not support in this context Via DB LINK

99封情书 提交于 2019-12-23 22:12:24

问题


I have a View and want to insert this via DB Link. But it's give error "ORA-02070: database does not support in this context". How can I solve this error ?

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;

View and Remote Table Types are same

Insert Statement:

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;

It's give error Insert Statement :(


回答1:


The problem has somehow to do with the views used in your view (DBA_SOURCES and DBA_ERRORS). See the discussion on the same variation with V$SESSION here and here.

Unfortunately I don't see a same simple solution as for V$SESSION (as proposed in the link above) and it seems to me that the problem is cause by the call of sys_context in the (nested view of the) view DBA_OBJECTS. So the propper solution is either in writing your own version of DBA_OBJECTS without using sys_context / USERENV or in creation a local copy of this data (e.g. in GTT)

Anyway there are two workaround:

1) revert the insert, i.e. connect to the remote DB ans insert from a view via DB LINK.

insert into t_demo
select * from v_demo@demo;

if connection to remote DB is not an option, you may

2) alternatively define a PROCEDURE on the remote DB and call it from the local DB

-- 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;
/


来源:https://stackoverflow.com/questions/34448918/ora-02070-database-does-not-support-in-this-context-via-db-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!