Oracle查看用户权限

模拟MySQL的show grants命令

首先创建用户,并且将示例帐号的表授权给他。

  1. sqlplus / as sysdba

  2. drop user edmond cascade;
  3. create user edmond identified by edmond;
  4. grant connect,resource to edmond;
  5. grant select,insert,update,delete on hr.employees to edmond;
  6. grant update(department_id),insert(department_name,department_id) on hr.departments to edmond;

作为DBA帐号登录,查看他的权限。

  1. set linesize 200;
  2. col privs_type format a10;
  3. col username format a20;
  4. col table_name format a35;
  5. col column_name format a25;
  6. col PRIVILEGE format a60;
  7. with t1 as 
  8. (
  9.     select upper('edmond') username from dual
  10. )
  11. select '角色' privs_type,'NULL' username,'NULL' table_name,'NULL' column_name,wm_concat(GRANTED_ROLE) PRIVILEGE from dba_role_privs,t1 where GRANTEE=t1.username group by '角色','NULL','NULL','NULL'
  12. union all
  13. select '表权限',owner,TABLE_NAME,'NULL',wm_concat(PRIVILEGE) PRIVILEGE from dba_tab_privs,t1 where GRANTEE=t1.username group by '表权限',owner,TABLE_NAME,'NULL'
  14. union all
  15. select '列权限',owner,TABLE_NAME,column_name,wm_concat(PRIVILEGE) PRIVILEGE from dba_col_privs,t1 where GRANTEE=t1.username group by '列权限',owner,TABLE_NAME,column_name;

作为普通用户登录,查看权限

  1. set linesize 200;
  2. col privs_type format a10;
  3. col username format a20;
  4. col table_name format a35;
  5. col column_name format a25;
  6. col PRIVILEGE format a60;
  7. with t1 as 
  8. (
  9.     select upper('edmond') username from dual
  10. )
  11. select '表权限' privs_type,TABLE_SCHEMA username,TABLE_NAME,'NULL' column_name,wm_concat(PRIVILEGE) PRIVILEGE from all_tab_privs,t1 where GRANTEE=t1.username group by '表权限',TABLE_SCHEMA,TABLE_NAME,'NULL'
  12. union all
  13. select '列权限',TABLE_SCHEMA,TABLE_NAME,column_name,wm_concat(PRIVILEGE) PRIVILEGE from all_col_privs,t1 where GRANTEE=t1.username group by '列权限',TABLE_SCHEMA,TABLE_NAME,column_name;

  14. 本文转自ICT时空dbasdk的博客,原文链接:Oracle查看用户权限 ,如需转载请自行联系原博主。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值