dblink的應用與管理

楊奇龍發表於2011-03-18
很多時候會遇到要從A 庫訪問到B庫中的資料的情況,oracle 提供了 database link 技術。建立dblink 有兩種方法:
1):不能在 tnsnames.ora檔案裡配置的情況。
yang@rac1>create database link linkyang
  2   connect to yang identified by yang
  3   using
  4   '( DESCRIPTION =
  5   (ADDRESS_LIST =
  6     (ADDRESS=(PROTOCOL = TCP )(HOST = 10.1.165.4)(PORT=1521))
  7   )
  8   (CONNECT_DATA=
  9     (SERVICE_NAME =oracl)
 10   )
 11   )';

Database link created.

yang@rac1>select count(1) from yang_old@linkyang;

  COUNT(1)
----------
    100000
2) ,如果可以在tnsnames.ora 檔案裡面配置,則如下:
在檔案裡面新增:
RAC =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.111)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = rac)
    )
  )
yang@rac1>create database link linkyang2
  2   connect to yang identified by yang
  3   using ‘rac’;
Database link created.
yang@rac1>select count(1) from yang_old@linkyang2;

  COUNT(1)
----------
    100000
3)刪除dblink
 yang@rac1>drop database link linkyang;
Database link dropped.
4)查詢已有的dblink
yang@rac1>select owner,object_name from dba_objects where object_type='DATABASE LINK';

OWNER           OBJECT_NAME
--------------- -------------------------
PUBLIC          ZZZZ
WANGYJ          MY_RAC
WANGYJ          UDB_TEST
YANG            LINKORACL
YANG            LINKYANG

5)同義詞的使用:yang_old@linkyang 可以使用同義詞來代替的。
yang@rac1>create synonym  oracl_yang_yangold for  yang_old@linkyang;
Synonym created.
yang@rac1>select count(1) from oracl_yang_yangold;

 COUNT(1)
----------
    100000

yang@rac1>

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22664653/viewspace-689947/,如需轉載,請註明出處,否則將追究法律責任。

相關文章