检查Oracle用户的特定权限

时间:2015-04-15 18:17:23

标签: oracle join

问题:我正在处理一个查询,该查询将生成所有Oracle用户的列表。我希望在查询中确定他们是否具有CONNECTAPPUSER的特定授予权限,并将其显示在一个表中。

我尝试了什么:我正在使用一个表,DBA_ROLE_PRIVS。此表显示了我需要的所有信息,但未能正确查询。我可以向所有拥有Connect权限的用户显示:

SELECT GRANTEE as "User Name", granted_role as "Connect"
FROM DBA_ROLE_PRIVS
WHERE GRANTED_ROLE='CONNECT';

我还可以向APPUSER的用户显示权限,只需将CONNECT替换为APPUSER

我的问题是在一个查询中显示两个权限。我尝试过使用不同的JOIN。但是,使用它似乎需要两个或更多表。我研究了一个" self-join"但是不明白如何使用两个WHERE子句。我尝试过这样的事情:

SELECT grantee as "User Name", t1.granted_role as "Connect", t2.granted_role as "APPUSER" 
FROM t1.DBA_ROLE_PRIVS join t2.DBA_ROLE_PRIVS on t1.GRANTEE = t2.GRANTEE 
WHERE t1.GRANTED_ROLE='CONNECT' and t2.GRANTED_ROLE='APP_USER';

我希望我的最终查询显示如下内容:

User Name         Connect        App User
----------       ----------     ---------- 
 Bob              CONNECT        APPUSER
 Sue                             APPUSER
 Nick             CONNECT        APPUSER
 Rob              CONNECT        

1 个答案:

答案 0 :(得分:1)

SELECT GRANTEE as "User Name", granted_role from DBA_ROLE_PRIVS where GRANTED_ROLE in ('CONNECT','APPUSER');

如果每个用户需要一行,每次访问需要两列,则可以使用此

select  c.GRANTEE as "User Name", a.granted_role as "Connect", c.granted_role as "APPUSER" 
FROM
(SELECT GRANTEE, granted_role from DBA_ROLE_PRIVS where GRANTED_ROLE = 'CONNECT')  a,

全外联接     (SELECT GRANTEE,来自DBA_ROLE_PRIVS的granted_role,其中GRANTED_ROLE ='APPUSER')c     在a.GRANTEE = c.GRANTEE;