如何显示具有" SELECT"的列表用户特定桌子的许可?

时间:2014-06-23 04:35:17

标签: oracle

我需要向用户授予Oracle数据库模式中的某些表,我之前已经创建了这个用户,但数据库有很多表(超过1000个表),所以我需要一个SQL查询来显示所有表用户可以连接。 该用户只能使用SELECT。

请帮我解决这个问题!

2 个答案:

答案 0 :(得分:4)

您可以使用以下查询。它将显示当前会话用户可以访问的所有表,

select * from user_tables;

要查看所有表格,

select * from all_tables;

列出已分配特定角色的所有用户

-- Change 'DBA' to the required role
select * from dba_role_privs where granted_role = 'DBA'

列出提供给用户的所有角色

-- Change 'PHIL@ to the required user
select * from dba_role_privs where grantee = 'PHIL';

列出授予用户的所有权限

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;

注意:取自http://www.adp-gmbh.ch/ora/misc/recursively_list_privilege.html

列出某个角色为哪些表提供SELECT访问权限?

-- Change 'DBA' to the required role.
select * from role_tab_privs where role='DBA' and privilege = 'SELECT';

列出用户可以从中选择的所有表格?

--Change 'PHIL' to the required user
select * from dba_tab_privs where GRANTEE ='PHIL' and privilege = 'SELECT';

列出所有可以在特定表上进行SELECT的用户(通过给予相关角色或通过直接授权(即授予对joe的授权选择))?此查询的结果还应显示用户具有此访问权限的角色,或者是否为直接授权。

-- Change 'TABLENAME' below
select Grantee,'Granted Through Role' as Grant_Type, role, table_name
from role_tab_privs rtp, dba_role_privs drp
where rtp.role = drp.granted_role
and table_name = 'TABLENAME' 
union
select Grantee,'Direct Grant' as Grant_type, null as role, table_name
from dba_tab_privs
where table_name = 'TABLENAME' ;

Reference

答案 1 :(得分:0)

查看http://docs.oracle.com/cd/B10501_01/server.920/a96521/privs.htm#15665

检查USER_SYS_PRIVS,USER_TAB_PRIVS,USER_ROLE_PRIVS表格。

使用它也很有帮助: -

select * from USER_ROLE_PRIVS where USERNAME='SAMPLE';
select * from USER_TAB_PRIVS where Grantee = 'SAMPLE';
select * from USER_SYS_PRIVS where USERNAME = 'SAMPLE';

Put" user"而不是示例来获取当前登录用户的信息。希望这有帮助!