Oracle存儲過程報錯ORA-02069: global_names parameter must be set to TRUE for this operation

今天開發給發郵件過來講一個存儲過程想經過dblink往目標庫insert數據,但報錯ORA-02069: global_names parameter must be set to TRUE for this operation,想讓我根據錯誤提示在數據庫上修改global_names參數修改成True。sql

先來看看官方文檔是如何介紹這個參數的:數據庫

GLOBAL_NAMES specifies whether a database link is required to have the same name as the database to which it connects.
If the value of GLOBAL_NAMES is false, then no check is performed. If you use or plan to use distributed processing, then Oracle recommends that you set this parameter to true to ensure the use of consistent naming conventions for databases and links in a networked environment.
session

從下面的查詢能夠看出global_names參數能夠在線進行修改的
oracle

zx@TEST>col name for a30
zx@TEST>select name,ISSES_MODIFIABLE,ISSYS_MODIFIABLE from v$parameter where name='global_names';

NAME			       ISSES_MODIFIABL ISSYS_MODIFIABLE
------------------------------ --------------- ---------------------------
global_names		       TRUE	       IMMEDIATE

看完了這個參數,再來看看開發的存儲過程代碼,其中insert語句中是用到了一個序列,因此致使了這個報錯。先在測試數據庫上建立了一個簡單的存儲過程來模擬現再這個問題ide

建立一個dblink測試

zx@TEST>create database link link_orcl connect to zx identified by "zx" using 'orcl';

Database link created.

zx@TEST>select * from dual@link_orcl;

DUM
---
X

先建立一個不帶序列的遠程insert的存儲過程
ui

zx@TEST>create or replace procedure pro_a as
  2  begin
  3  insert into t2@link_orcl (c1) values('a');
  4  commit;
  5  end;
  6  /

Procedure created.

執行這個存儲過程,觀察結果,數據能夠正常插入
this

zx@TEST>select * from t2@link_orcl;

no rows selected

zx@TEST>exec pro_a;

PL/SQL procedure successfully completed.

zx@TEST>select c1 from t2@link_orcl;

C1
---
a

建立一個序列,並修改上面的存儲過程spa

zx@TEST>create sequence seq_a;

Sequence created.

zx@TEST>create or replace procedure pro_a as
  2  begin
  3  insert into t2@link_orcl (c1,n1) values('a',seq_a.nextval);
  4  commit;
  5  end;
  6  /
  
Procedure created.

執行修改後的存儲過程,重現上面的錯誤ORA-02069orm

zx@TEST>exec pro_a;
BEGIN pro_a; END;

*
ERROR at line 1:
ORA-02069: global_names parameter must be set to TRUE for this operation
ORA-06512: at "ZX.PRO_A", line 3
ORA-06512: at line 1

先在session層面修改global_names參數,再次執行存儲過程,又出現了新的錯誤:說兩端的數據庫名不一致。

zx@TEST>alter session set global_names = true;

Session altered.

zx@TEST>exec pro_a;
BEGIN pro_a; END;

*
ERROR at line 1:
ORA-02085: database link LINK_ORCL connects to ORCL
ORA-06512: at "ZX.PRO_A", line 3
ORA-06512: at line 1

zx@TEST>!oerr ora 2085
02085, 00000, "database link %s connects to %s"
// *Cause: a database link connected to a database with a different name.
//  The connection is rejected.
// *Action: create a database link with the same name as the database it
//  connects to, or set global_names=false.

那如今問題來了,實際生產中源端和目標端的數據庫名確定是不一致的,因此修改這個參數並不能解決這個問題。

只能想其餘的辦法來繞過這個錯誤,這裏給開發提了兩個建議:

一、把存儲過程部署到目標端來避免遠程insert中調用sequence

二、在源端存儲過程當中引入臨時表,先把數據插入臨時表,再從臨時表插入到遠端表。


在MOS上搜到了一個相關文檔(ORA-02069 DURING REMOTE INSERT OF A LOCAL SEQUENCE (文檔 ID 1047673.6))跟咱們的問題描述一致。


官方文檔:http://docs.oracle.com/cd/E11882_01/server.112/e40402/initparams098.htm#REFRN10065

相關文章
相關標籤/搜索