2014年12月16日 星期二

ORA-02070: database does not support in this context

現象:
insert into remote_table@dblink(columns.....)
select columns..... from local_view ;
==> ORA-02070: database  does not support  in this context

解決方式:
1. 將 select columns..... from local_view 換成 select columns..... from local_table.....,不要使用view,改成table
2. 將procedure 由 local DB執行改為 remote DB執行,例如
    insert into local_table(columns...) select columns... from remote_view@dblink ;
3. 將 procedure 改成 cursor 運作

參考來源:
ORA-2070 during an remote Insert over Database link while selecting from local dictionary view (Doc ID 744219.1)

APPLIES TO:

Oracle Database - Enterprise Edition - Version 7.2.3.0 to 11.2.0.2 [Release 7.2.3 to 11.2]
Information in this document applies to any platform.

SYMPTOMS

ORA-2070 Error occurs when inserting into remote Table with Select from local Dictionary Views.
For Example :"Ora10g" is Local Database and "Dblink" is name of Database link that connects to Remote Database where Table T2 exists..T2 has same DDL structure as V$instance.
On executing below Remote Insert Statement, ORA-02070 Error occurs
insert into t2@ora10g(select *from v$instance)
*
ERROR at line 1:
ORA-02070: database does not support in this context


CHANGES

CAUSE


02070, 00000, "database %s%s does not support %s in this context"
// *Cause: The remote database does not support the named capability in
// the context in which it is used.
// *Action: Simplify the SQL statement.

//
The operation is unsupported which is clear from Bug 469264 "INSERT INTO REMOTE TABLE SELECT FROM LOCAL DICTIONARY VIEW GIVES 2070"
"The error is not a bug, but I've changed the message to print the name ofthe operation (in this case we will print "USERENV" instead of "operator 105") to make diagnosing possible."



SOLUTION

Workaround
You can use any one of 2 Solutions as shown below to resolve the issue:

1) Use Insert Statement in Remote Database and use Database links in Select statements .
   
insert into t2 (select * from v$instance@Dblink);
commit;

   Here Dblink is the name of Database Link that connects to Database where  information of table V$instance are taken.

2) Use a PL/Sql cursor in local Database to fetch Data from Local Database and then Insert into remote Database as shown in below Example :


declare
cursor c1 is select * from V$instance;


begin
for i in c1 loop
insert into T2@Dblink values(i.INSTANCE_NUMBER ,
i.INSTANCE_NAME ,
i.HOST_NAME,
i.VERSION ,
i.STARTUP_TIME ,
i.STATUS ,
i.PARALLEL ,
i.THREAD# ,
i.ARCHIVER ,
i.LOG_SWITCH_WAIT ,
i.LOGINS ,
i.SHUTDOWN_PENDING,
i.DATABASE_STATUS ,
i.INSTANCE_ROLE ,
i.ACTIVE_STATE ,
i.BLOCKED ) ;
end loop;
end;
/
commit;

Here "Dblink" is the name of Database link that connects
from Local database (where information on V$instance is taken)
to Remote database(where table T2 exists).

沒有留言:

張貼留言