使用Oracle DBLink進行資料庫之間對象的訪問操作

來源:互聯網
上載者:User

標籤:creat   Owner   ora   http   sdn   test   之間   details   ddr   

Oracle中內建了DBLink功能,它的作用是將多個oracle資料庫邏輯上看成一個資料庫,也就是說在一個資料庫中可以操作另一個資料庫中的對象,例如我們建立了一個資料database1,我們需要操作資料庫database2中的表,或者我們需要操作遠程機器上資料庫database3中的表,我們就可以使用dblink這個強大的功能!
1、我們如果要建立全域的DBLink,就是說無論什麼角色都可以使用,那麼我們需要先確定使用者是否有DBLink許可權,如果沒有則需要使用sysdba角色給使用者授權:
查看使用者是有有DBLink許可權:
select * from user_sys_privs where privilege like upper(‘%DATABASE LINK%‘);
沒有,則使用sysdba授權:
grant create public database link to dbusername;

2、使用語句建立DBLink:
create database link 要建立的dblink名稱
connect to 要串連資料庫的使用者名稱 identified by 要串連資料的密碼
using ‘(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 串連資料庫主機IP地址)(PORT = 連接埠號碼))
)
(CONNECT_DATA =
(SERVICE_NAME = 串連資料庫服務名)
)
)‘;
如果建立全域 dblink,必須使用 systm 或 sys 使用者,在 database 前加 public:
create public database....
例如,在testdb2中建立test_dblink,來操作主機192.168.1.254中testdb1資料庫:
create database link tset_dblink
connect to username identified by password1
using ‘(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.254)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = testdb1)
)
)‘;

3、使用DBLink:
查詢另一個資料庫中的資料,其他修改、刪除是一樣的使用,都是另一個資料庫表名@本資料庫建立dblink名稱:
select xxx FROM 表名@dblink名稱;
例如我們在testdb2中使用dblink查看testdb1中tb_user表中的資料:
select * from [email protected]_dblink;
查看資料中建立的dblink:
select owner,object_name from dba_objects where object_type=‘DATABASE LINK‘;
select * from dba_db_links;
刪除相應的dblink:
drop database link dblink名稱;
關閉dblink串連:
alter session close database link ‘dblink_name‘
建立和刪除視圖:
create or replace view 視圖名 as (select 欄位 from 使用者.表名@dblink1);
drop view 視圖名;

本文轉自:http://blog.csdn.net/harderxin/article/details/39639181

 

使用Oracle DBLink進行資料庫之間對象的訪問操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.