创建DBLINK的方法:
1. create public database link dblink
connect to totalplant identified by totalplant
using ‘(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = LOCALHOST)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = prd.gdc)
)
)‘;
语法解释:create public database link DBLINK名字(自己随便起)
connect to 用户名 identified by 密码
using ‘(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 要连接的数据库所在服务器的IP地址)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = 要连接的数据库的在本地的服务名(即要连接的数据库的SID))
)
)‘;
2. 如果创建private的DBLINK
create database link dblink
connect to totalplant identified by totalplant
using ‘(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = LOCALHOST)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = prd.gdc)
)
)‘;
四. 连接成功后从所连接的数据库中取数的方法:
1. select * from [email protected];
说明:只需在表名的后面加上"@DBLINK名字"即可。
五. 在当前数据库下查看所有的DBLINK的方法:
1. select * from dba_db_links;
六. 删除当前数据库下的一个指定的DBLINK的方法:
1. 如果创建的是一个public的DBLINK,删除时需要用
drop public database link dblink;
2. 如果创建的是一个private的DBLINK,删除时需要用
drop database link dblink;
说明:drop public database link DBLINK名字;
七. 查看当前数据库的全局数据库名的方法:
1. select * from global_name;
八. 查看当前用户具有哪些针对DBLINK的权限的方法:
1. SELECT DISTINCT PRIVILEGE AS "Database Link Privileges"
FROM ROLE_SYS_PRIVS
WHERE PRIVILEGE IN ( ‘CREATE SESSION‘,‘CREATE DATABASE LINK‘,
‘CREATE PUBLIC DATABASE LINK‘);