1. 程式人生 > >同一伺服器上不同資料庫之間同步表資料

同一伺服器上不同資料庫之間同步表資料

在同一個伺服器上有兩個資料庫A和B,現在想取B資料庫中的某個表中的資料插入到A中,做法是:

1、首先在A資料庫中建立一個dblink,其中testLink是dblink名字隨便取,username跟password都是B資料庫的登入名跟密碼;

create public database link testLink
connect to username identified BY password
using ‘(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.230)(PORT = 1521))
(LOAD_BALANCE = yes)
(FAIL_OVER = yes)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)’;

2、從資料庫B中的相關表取出資料插入到A資料庫中的相關表對應的欄位通過 “表名@dblink名稱”找到B中的表,格式如下
Insert into Table2(field1,field2,…) select value1,value2,… from Table1

insert into T_ZD_XZQH
(id,dm,czbz,jc,qc,pyt)
select seq_t_zd_mz.nextval,d.dm,’1′,d.jc,d.qc,d.pyt
from [email protected] d
where d.bs=’y’;
3、檢視已建立的dblink

select * from dba_db_links;–或
select owner,object_name from dba_objects where object_type=’DATABASE LINK’;

4、同一資料庫服務地址下,以DBA身份登入訪問其他使用者下的表直接在表明前面加上使用者名稱即可。