暂无图片
Oracle 查询具有某权限的所有用户
我来答
分享
Thomas
2022-11-03
Oracle 查询具有某权限的所有用户

比如要查出具有create database link权限的所有用户,这个权限有可能是显式授予该用户的,也有可能是通过ROLE的方式授予的。请给出SQL。

我来答
添加附件
收藏
分享
问题补充
2条回答
默认
最新
农夫三拳

select u.username
from dba_users u
where u.username in
(select rp.grantee
from dba_role_privs rp
where rp.granted_role in
(select a.grantee
from dba_sys_privs a
where a.privilege = 'CREATE DATABASE LINK'))
or u.username in
(select sp.grantee
from dba_sys_privs sp
where sp.privilege = 'CREATE DATABASE LINK')



暂无图片 评论
暂无图片 有用 1
猫瞳映月
2022-12-15
还得是娃哈哈大佬厉害,什么特殊的需求都能实现,学到了
Thomas

哇哈哈,应该不全面吧。因为有通过ROLE级联授权的方式:

SQL> create role abc;

Role created.

SQL> create role def;

Role created.

SQL> grant create session to abc;

Grant succeeded.

SQL> grant abc to def;

Grant succeeded.

SQL> create user test identified by test;

User created.

SQL> grant def to test;

Grant succeeded.

--查询TEST用户是否具有create session权限,结果没有。我在你的查询外面加了个外套,外套里限制条件是username='TEST'
select * from (
select u.username
from dba_users u
where u.username in
(select rp.grantee
from dba_role_privs rp
where rp.granted_role in
(select a.grantee
from dba_sys_privs a
where a.privilege = 'CREATE SESSION'))
or u.username in
(select sp.grantee
from dba_sys_privs sp
where sp.privilege = 'CREATE SESSION')) where username='TEST';

no rows selected

SQL> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics, Real Application Testing
and Unified Auditing options

test可以登录SQLPLUS
[oracle@iZ94t0nyo72Z ~]$ sqlplus test/test

SQL*Plus: Release 12.1.0.2.0 Production on Thu Nov 3 16:17:51 2022

Copyright (c) 1982, 2014, Oracle. All rights reserved.


Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics, Real Application Testing
and Unified Auditing options


Session altered.

Elapsed: 00:00:00.00

SQL> exit

暂无图片 评论
暂无图片 有用 1
农夫三拳
2022-11-03
唉。子子孙孙无穷匮也
virvle
2022-11-08
O(∩_∩)O哈哈~学到了
回答交流
提交
问题信息
请登录之后查看
邀请回答
暂无人订阅该标签,敬请期待~~
暂无图片墨值悬赏