--DBLink;
--查看DBLink
select * from dba_db_links;
--授权
grant create public database link;
--或者create database link to myAccount;

--创建(如果在create之后不加public,则创建的dblink就不是公共的,就只有创建者可以使用了.)
create database link TO_anxin connect to anxindev identified by axdev20170308
   using '(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 139.199.7.38)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)';

--查询
select * from anxindev.fdcom@TO_anxin;

-- 不想让使用的人知道database link的名字的时候
-- 建一个别名(同义词)包装一下

创建同义词权限:grant create synonym to scott
CREATE SYNONYM FDTest FOR FDTest@TO_anxin;
SELECT * FROM FDTest;
--删除同义词: [public]
drop synonym FDTest;
--查看所有同义词:
select * from dba_synonyms where table_name like '%fdcom';
-- 或者,也可以建立一个视图来封装
--CREATE VIEW table_name AS SELECT * FROM table_name@database link;

--删除
drop public database link TO_anxin;
-- 删除非public类型的database link
-- 注意:只有owner自己能删除自己的非public类型database link
DROP database link TO_anxin;