数据库之间的链接建立在DATABASE LINK上。要创建一个DB LINK,必须先在每个数据库服务器上设置链接字符串。
1、 配置TNS , $ORACLE_HOME/NETWORK/ADMIN/tnsname.ora
10gstandby =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = HFCC-KF-3068)(PORT = 1522))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = 10gstandby)
)
)
2、创建数据库链接,
create public database link DB_LINK_NAME connect to TargetDatabaseUserName identified by TargetDatabasePassword using 'TargetDatabaseSIDName';
注:TargetDatabaseSIDName为该Oracle数据库所在的主机上的tnsnames.ora文件里边定义的数据库连接串。
SQL>create public database link dvd connect to system identified by system using 'orcl10g';
或者使用:
create PUBLIC database link LINK_NAME
connect to USER identified by PWD
using '(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)';
则创建了一个以system用户和orcl10g数据库的链接dvd,我们查询dvd数据:
SQL>select * from all_users@dvd;
这样就可以把本地和远程的数据做成一个整体来处理。
3、建立同义词,为了使有关分布式操作更透明,ORACLE数据库里有同义词的对象synonym
SQL>create synonym synTest for all_users@dvd;
于是就可以用synTest来替代带@符号的分布式链接操作all_users@dvd;
4、查看所有的数据库链接:
SQL>select owner,object_name from dba_objects where object_type='DATABASE LINK';
5、查看数据库连接
sql> select owner, db_link from dba_db_links;
ower db_link
public DVD.REGRESS.RDBMS.DEV.US.ORACLE.COM
6、删除数据库连接
先从第5步中查看数据库连接,取得其db_link的名称
sql>drop public database link DVD.REGRESS.RDBMS.DEV.US.ORACLE.COM
数据库连接巳丢弃
oracle视频教程请关注:http://u.youku.com/user_video/id_UMzAzMjkxMjE2.html