Oracle同義字+dblink的實際應用

來源:互聯網
上載者:User

Oracle同義字+dblink的實際應用

Oracle同義字+dblink的實際應用

業務需求:原資料庫(10.2.0.4.0),新資料庫(11.2.0.3)
由於程式的需求原因,現在需要把新庫上的某個使用者直接映射到老庫使用者下:

1. 備份原庫的使用者
nohup exp scott/scott OWNER=scott BUFFER=10240000 STATISTICS=none RESUMABLE=y FILE=scott_all_exp.dmp LOG=scott_all_exp.log &

2. 刪除原庫的使用者下的表
set linesize 180 pagesize 1000
SELECT 'DROP TABLE '||table_name||' CASCADE CONSTRAINTS PURGE;' FROM user_tables;

得出SQL的命令vi儲存到droptable.sql
然後SQL> @droptable

3. 在原庫上建立到新庫的dblink
create public database link link167 connect to scott identified by scott using '(DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.167)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = NEWDB)
    )
  )';

測試dblink可用:
select * from dual@link167;

4. 在原庫上建立同義字
create synonym MDRT_12E92$ for MDRT_12E92$@link167;

在新庫查詢user_tables得到table_name的列表,
set pagesize 1500
select table_name from user_tables;

命令用UE列編輯處理好,vi儲存到createsynonym.sql
然後SQL> @createsynonym

相關文章

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.