1、查询当前是否具有创建DBlink的权限:
select * from user_sys_privs where privilege like upper('%DATABASE LINK%');
如果没有权限,先授权:
grant CREATE DATABASE LINK,DROP DATABASE LINK to scott;
2、查询当前已存在DBLink
select * from all_db_links;
3、创建DBLink
create database link dblink_20191015
connect to scott identified by "123456"
using '(DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = orcl)))';
dblink_20191015:DBLink名称
scott:连接用户
“123456”:密码(注:如果是数字开头,必须要用双引号引起来)
4、查询数据
select * from employee@dblink_20191015
5、删除DBLink
drop database link dblink_20191015;(其中public是公共的)