查找有多少用户拥有表创建权限

时间:2014-10-25 14:57:10

标签: sql oracle oracle11g

我想了解有多少用户有权使用元数据在Oracle 11g数据库中创建表。

我应该写什么样的查询? (我不希望它变得非常复杂)。

3 个答案:

答案 0 :(得分:1)

select count(distinct usr) 
from (
  select auth, tp, connect_by_root auth usr, connect_by_root tp tp_usr
  from (
    select null grantee, username auth, 'user' tp from dba_users
    union
    select grantee, granted_role, 'role' from dba_role_privs
    union
    select grantee, privilege, 'priv' from dba_sys_privs
  )
  start with grantee is null
  connect by grantee = prior auth
) where tp_usr = 'user' and auth in ('CREATE TABLE', 'CREATE ANY TABLE');

此查询还以递归方式扫描授予的角色。但是,我仍然不确定它是否会为所有可以创建表的用户提供。

答案 1 :(得分:0)

看到你到目前为止所做的事情会很好。我可以让你先尝试使用以下内容:

dba_usersdba_sys_privs

您正在寻找的权限是CREATE ANY TABLE

请搜索它们并提出您的尝试,我很乐意为您提供进一步的帮助。

答案 2 :(得分:0)

拥有此类权限的所有用户和角色:

select *
from dba_sys_privs
where privilege = 'CREATE TABLE' or privilege = 'CREATE ANY TABLE';

此外,您还需要查看DBA_ROLE_PRIVS,因为用户可以使用角色间接获得权限。