B,在目标机上用sqlplus user/pwd登录。
C,用如下命令建立DB Link:
create public database link AAA_LINK connect to user identified by pwd using 'AAA';
命令说明:
CREATE PUBLIC DATABASE LINK 数据库链接名 CONNECT TO 用户名 IDENTIFIED BY 密码 USING ‘本地配置的数据的实例名’;
如果建立成功,会提示:Database link created.
2,使用如下脚本,即可同步数据表:
<IMG title="轻松建立Oracle DB Link" alt="轻松建立Oracle DB Link" src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top real_src="http://www.blogjava.net/Images/OutliningIndicators/None.gif">#!/bin/sh
<IMG title="轻松建立Oracle DB Link" alt="轻松建立Oracle DB Link" src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top real_src="http://www.blogjava.net/Images/OutliningIndicators/None.gif"># to sync table A to BBB database from AAA database
<IMG title="轻松建立Oracle DB Link" alt="轻松建立Oracle DB Link" src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top real_src="http://www.blogjava.net/Images/OutliningIndicators/None.gif">sqlplus user/pwd@BBB <<EOF #这里是BBB上的数据库和密码还有实例名,请按照实际情况修改
<IMG title="轻松建立Oracle DB Link" alt="轻松建立Oracle DB Link" src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top real_src="http://www.blogjava.net/Images/OutliningIndicators/None.gif">truncate table A;
<IMG title="轻松建立Oracle DB Link" alt="轻松建立Oracle DB Link" src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top real_src="http://www.blogjava.net/Images/OutliningIndicators/None.gif">insert into A
<IMG title="轻松建立Oracle DB Link" alt="轻松建立Oracle DB Link" src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top real_src="http://www.blogjava.net/Images/OutliningIndicators/None.gif">select * from b_schema.A@AAA_LINK; #这里是指向要同步的来源表,表名必须是<表所有者>.<表名>@<dblink name>
<IMG title="轻松建立Oracle DB Link" alt="轻松建立Oracle DB Link" src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top real_src="http://www.blogjava.net/Images/OutliningIndicators/None.gif">commit;
PS:需要DB支持Advanced replication功能,是否支持,可用如下SQL查看:
<IMG title="轻松建立Oracle DB Link" alt="轻松建立Oracle DB Link" src="http://www.blogjava.net/Images/OutliningIndicators/None.gif" align=top real_src="http://www.blogjava.net/Images/OutliningIndicators/None.gif">select * from v$option where PARAMETER='Advanced replication';
如果是返回True就表示支持。