Oracle 用dblink 跨庫導資料

來源:互聯網
上載者:User

一般都會用imp exp 備份和匯入資料庫  但是有些時候 需要比較靈活的從兩個資料庫之間取資料 我這裡用到的是oralc的dblink方式。

首先監聽器tnsnames.ora這個檔案能串連到遠程要建立dblink的資料庫。

-- 建立dblink   MANAGER為遠端資料庫的使用者名稱 password 為遠端資料庫的密碼, orcl為監聽器連好的連結名稱

  1. create database link DDD.REGRESS.RDBMS.DEV.US.Oracle.COM   
  2.   connect to MANAGER  identified by  password      
  3.   using 'orcl';  

這樣就可以串連到 orcl資料庫 靈活的取每一張表的資料了

--兩個資料庫都存在 tb_demo表  這是本表插入

--查詢資料 sql和本地一樣了  只是後面加個@DDD.REGRESS.RDBMS.DEV.US.ORACLE.COM  就等於是dblink連好的遠端資料庫了

  1. INSERT INTO tb_demo   
  2.               SELECT * FROM tb_demo@DDD.REGRESS.RDBMS.DEV.US.ORACLE.COM   
  3.               where iyear=2011   
  4.               and imonth=8  and flag=0  

相關文章

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.