您的位置:首页 > 数据库

dblink实现一个数据库用户只能查另一个库用户的数据

2018-02-07 15:40 417 查看
--a库:10.2.0.5 csdb
--b库:11.2.0.4 orcl

用a库的用户查询b库用户的数据
a库tnsnames.ora文件中添加对方内容
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.101)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)

a端 tnsping orcl

a端创建用来查询b端test下表的用户
create user testa identified by oracle_4U
default tablespace abctest
temporary tablespace temp;

grant create session,create database link to testa;

b端创建用来查询test下表的用户
create user testb identified by oracle_4U
default tablespace abctest
temporary tablespace temp;

grant create session to testb;

test用户下授权查询所有表和视图、序列给testb用户,执行查询结果
test用户执行: 	select 'grant select on test.' || tname || ' to testb;' from tab;
sys用户执行:  	select 'grant select on ' || sequence_name || ' to testb;' from dba_sequences where sequence_owner='TEST';

a端testa用户创建dblink,只能查询,无法修改
[oracle@10g admin]$ sqlplus  testa/oracle_4U

SQL*Plus: Release 10.2.0.5.0 - Production on Wed Feb 7 02:16:29 2018

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> create database link selectlink connect to testb identified by oracle_4U using 'ORCL';

Database link created.

SQL> select * from test.worker@selectlink;

WNO       WNAME
--------- --------------------
001       adam
002       lilith

SQL> insert into test.worker@selectlink values('003','eva');
insert into test.worker@selectlink values('003','eva')
*
ERROR at line 1:
ORA-01031: insufficient privileges
ORA-02063: preceding line from SELECTLINK
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  dblink 只能查询
相关文章推荐