Oracle兩個數據庫聯合查詢,使用Oracle DBLink

 

  • 建立dblink
-- Create database link 
create shared database link COPYCITY_BZTOMY
connect to db_A identified by db_A
authenticated by db_B identified by db_B
using '192.168.0.141/orcl';             --說明有兩個數據庫db_A密碼db_A和db_B密碼db_B  該SQL語句在db_A中執行,表示在db_A中可使用b_B中的表
  • 檢查dblink是否可用數據庫

select * from b_djb@COPYCITY_BZTOMY   --假設表b_djb在db_B庫中,那麼咱們在db_A 庫中執行以上SQL語句,檢查是否能正常查詢db_B中的數據
  • 若是有clob字段建立臨時表,先賦值給臨時表,最後將臨時表賦值給目標表,若是沒有clob字段直接跳到最後一步操做
--建立臨時的 商城信息表
--drop table city_scspxxb_temp
truncate table 
create global temporary table city_scspxxb_temp as 
select *
from city_scsbxxb ;
  • 將數據導入到臨時表中
insert into city_scspxxb_temp select * from city_scsbxxb@COPYCITY_BZTOMY where city_scspxxid='27405'  --加條件
  • 將臨時表的數據導入目標庫
insert into city_scsbxxb@COPYCITY_BZTOMY select * from city_scspxxb_temp
相關文章
相關標籤/搜索