db link

-- 查看当前用户能访问的所有DBLink
SELECT * FROM USER_DB_LINKS;

-- 或者查看数据库中的所有公有DBLink(需要权限)
col host for a20
col username for a20
col owner for a20
col db_link for a20
set line 2000
SELECT * FROM DBA_DB_LINKS;

删除公有DBLink(需要DBA权限)
DROP PUBLIC DATABASE LINK OA_TO_MES;

举例:
如何OA系统想要访问MES系统

  1. OA数据库tnsnames.ora添加mes的连接信息
    TPMESDB =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.2.128.27)(PORT = 1521))
    (CONNECT_DATA =
    (SERVER = DEDICATED)
    (SERVICE_NAME = tpmesdb)
    )
    )

2.MES数据库上面创建一个test1用户,并把其他用户的表的查询权限给test1
CREATE USER test1 IDENTIFIED BY "test1";
GRANT CREATE SESSION TO test1;
GRANT SELECT ON mes_schema.projects TO test1;

3.OA系统上面创建dblink
创建DBLink
sql
-- 以DBA用户登录OA系统数据库
CREATE PUBLIC DATABASE LINK OA_TO_MES
CONNECT TO test1 IDENTIFIED BY "test1"
USING 'TPMESDB';

4.在OA数据库上面查询MES数据库的数据
select * from test.test1@oa_to_mes;

posted @ 2025-11-29 17:55  ocmji  阅读(3)  评论(0)    收藏  举报