在Oracle11g 中新建用户,授予只读用户权限详细步骤 (批量执行授权多表查询)

2016/10 28 04:10

 

1、创建新用户 

create user macs identified by 123456 default tablespace tablespacename;

 

2、授权connect 和 synonym 

grant connect to macs;

grant create synonym to macs;

 

3、授权查询表的权限

grant select on tablespacename.M_TMP to t1;

 

4、创建同义词

create or replace SYNONYM MACS.M_TMP FOR tablespacename.M_TMP;

 

5、完成。测试查询

 

备注:

1、批量执行授权多表查询权限的查询语句

select ‘grant select on ‘||owner||’.’||object_name||’ to t1;’
from dba_objects
where owner in (‘tablespacename’)
and object_type=’TABLE’;

 

2、批量执行创建同义词查询语句

 SELECT ‘create or replace SYNONYM MACS.’ || object_name|| ‘ FOR ‘ || owner || ‘.’ || object_name|| ‘;’  
 from dba_objects 
 where owner in (‘tablespacename’)
 and object_type=’TABLE’;