select * from user_sys_privs t where t.privilege like upper('%link%');
在sys用户下,显示结果为:
SYS CREATE DATABASE LINK NO
SYS DROP PUBLIC DATABASE LINK NO
SYS CREATE PUBLIC DATABASE LINK NO
可以看出在数据库中dblink有三种权限:
CREATE DATABASE LINK--所创建的dblink只能是创建者能使用,别的用户使用不了
CREATE PUBLIC DATABASE LINK--public表示所创建的dblink所有用户都可以使用
DROP PUBLIC DATABASE LINK--删除指定dblink
如果想要改变某个用户的权限,需要在sys用户下修改:
grant CREATE PUBLIC DATABASE LINK,DROP PUBLIC DATABASE LINK to scott;
查看dblink,有两种方式,分别如下:
①.
select owner,object_name from dba_objects where object_type='DATABASE LINK';
②.
select * from dba_db_links;
2. 创建dblink
create public database link LINK_NAME
connect to USRNAME identified by "PASSWORD"
using
'(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = XXX.XXX.XXX.XXX)(PORT = 1521))
(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = XXX))
)';