限制用户访问数据库另外一个用户的对象,reference how to clone user privileges [ID 473317.1]

故事背景:

作为非db 开发技术人员,当有如题这种需求时候,作为运维人员需要告诉开发哪些用户目前有哪些权限即可:

 

1.当需要知道某个用户角色和角色的具体权限时候,如下脚本即可满足:

select lpad(' ', 2*level) || granted_role "User, his roles and privileges" 
from ( /* THE USERS */ select null grantee, username granted_role 
from dba_users 
where username like upper('%&enter_username%') 
/* THE ROLES TO ROLES RELATIONS */ 
union 
select grantee, granted_role 
from dba_role_privs 
/* THE ROLES TO PRIVILEGE RELATIONS */ 
union 
select grantee, privilege 
from dba_sys_privs ) 
start with grantee is null connect by grantee = prior granted_role

/*input the username which you want to query*/
Enter value for enter_username: scott 
old 12: username like upper('%&enter_username%') 
new 12: username like upper('%scott%')
 
##Script Output
User, his roles and privileges 
-------------------------------------------------------------------------------- 
SCOTT 
CONNECT 
CREATE SESSION 
RESOURCE 
CREATE CLUSTER 
CREATE INDEXTYPE 
CREATE OPERATOR 
CREATE PROCEDURE 
CREATE SEQUENCE 
CREATE TABLE 
CREATE TRIGGER 

User, his roles and privileges 
-------------------------------------------------------------------------------- 
CREATE TYPE 
UNLIMITED TABLESPACE 

13 rows selected.

 
2.但当某个schema中出现新增的对象(表、视图、sequence等等)时候,我们需要一个自动的添加这种权限给你想需要赋权的用户:
CONN SCOTT/TIGER

BEGIN
  FOR x IN (SELECT table_name FROM user_tables) LOOP
    EXECUTE IMMEDIATE 'GRANT SELECT ON ' || x.table_name || ' TO HR';
  END LOOP;
END;

另:如果需要其他权限可在上述权限中增加 grant privilege 即可 <感谢彪彪提供>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值