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