Oracle创建只读账号

#先创建一个用户read_only,密码123456

create user read_only identified by "123456" 
default tablespace read_only;

#给他一些权限,包括连接权限,因为他要创建同义词,还需要给他同义词

grant connect to read_only ;
grant create synonym to read_only;
grant create session to read_only;

#授权=因为需要把需要查询的库(假如库为DATA),的所有表的查询权限给read_only。所以需要所有表的grant select on table_name to read_only语句,不可能一句一句去写,因此用select 吧所有的grant语句查出来直接执行,注意:DATA要大写,不然结果是空的

select 'grant select on '||owner||'.'||object_name||' to read_only;'
 from dba_objects
 where owner in ('DATA')
 and object_type='TABLE';

#把上述语句查询出来的结果(如下图)全部选中复制出来,在SOCIETY_WUTONG_H5 下执行一遍

select 'create or replace SYNONYM read_only.' || object_name|| ' FOR ' || owner || '.' || object_name|| ';' 
from dba_objects
where owner in ('DATA')
and object_type='TABLE';

你可能感兴趣的:(Oracle创建只读账号)