Answers:
如果您不仅需要直接表授予(例如,通过角色进行的授予,诸如选择任何表之类的系统特权等),还可以使用以下一些附加查询:
用户的系统特权:
SELECT PRIVILEGE
FROM sys.dba_sys_privs
WHERE grantee = <theUser>
UNION
SELECT PRIVILEGE
FROM dba_role_privs rp JOIN role_sys_privs rsp ON (rp.granted_role = rsp.role)
WHERE rp.grantee = <theUser>
ORDER BY 1;
直接授予表/视图:
SELECT owner, table_name, select_priv, insert_priv, delete_priv, update_priv, references_priv, alter_priv, index_priv
FROM table_privileges
WHERE grantee = <theUser>
ORDER BY owner, table_name;
对表/视图的间接授予:
SELECT DISTINCT owner, table_name, PRIVILEGE
FROM dba_role_privs rp JOIN role_tab_privs rtp ON (rp.granted_role = rtp.role)
WHERE rp.grantee = <theUser>
ORDER BY owner, table_name;
role_role_privs
桌,然后CONNECT BY PRIOR granted_role = role
递归到传递角色特权将很有趣……
抱歉,但是如果您从其他用户(例如SYS)运行select,那么从all_tab_privs_recd中进行选择,其中grantee ='您的用户'不会提供任何输出,除了公共授权和当前用户授权。如文档所述,
ALL_TAB_PRIVS_RECD描述以下类型的授予:
Object grants for which the current user is the grantee Object grants for which an enabled role or PUBLIC is the grantee
因此,如果您是DBA,并且想要列出特定用户(而不是SYS本身)的所有对象授予,则不能使用该系统视图。
在这种情况下,您必须执行更复杂的查询。这是从TOAD中获取(跟踪)的,用于为特定用户选择所有对象授权:
select tpm.name privilege,
decode(mod(oa.option$,2), 1, 'YES', 'NO') grantable,
ue.name grantee,
ur.name grantor,
u.name owner,
decode(o.TYPE#, 0, 'NEXT OBJECT', 1, 'INDEX', 2, 'TABLE', 3, 'CLUSTER',
4, 'VIEW', 5, 'SYNONYM', 6, 'SEQUENCE',
7, 'PROCEDURE', 8, 'FUNCTION', 9, 'PACKAGE',
11, 'PACKAGE BODY', 12, 'TRIGGER',
13, 'TYPE', 14, 'TYPE BODY',
19, 'TABLE PARTITION', 20, 'INDEX PARTITION', 21, 'LOB',
22, 'LIBRARY', 23, 'DIRECTORY', 24, 'QUEUE',
28, 'JAVA SOURCE', 29, 'JAVA CLASS', 30, 'JAVA RESOURCE',
32, 'INDEXTYPE', 33, 'OPERATOR',
34, 'TABLE SUBPARTITION', 35, 'INDEX SUBPARTITION',
40, 'LOB PARTITION', 41, 'LOB SUBPARTITION',
42, 'MATERIALIZED VIEW',
43, 'DIMENSION',
44, 'CONTEXT', 46, 'RULE SET', 47, 'RESOURCE PLAN',
66, 'JOB', 67, 'PROGRAM', 74, 'SCHEDULE',
48, 'CONSUMER GROUP',
51, 'SUBSCRIPTION', 52, 'LOCATION',
55, 'XML SCHEMA', 56, 'JAVA DATA',
57, 'EDITION', 59, 'RULE',
62, 'EVALUATION CONTEXT',
'UNDEFINED') object_type,
o.name object_name,
'' column_name
from sys.objauth$ oa, sys.obj$ o, sys.user$ u, sys.user$ ur, sys.user$ ue,
table_privilege_map tpm
where oa.obj# = o.obj#
and oa.grantor# = ur.user#
and oa.grantee# = ue.user#
and oa.col# is null
and oa.privilege# = tpm.privilege
and u.user# = o.owner#
and o.TYPE# in (2, 4, 6, 9, 7, 8, 42, 23, 22, 13, 33, 32, 66, 67, 74, 57)
and ue.name = 'your user'
and bitand (o.flags, 128) = 0
union all -- column level grants
select tpm.name privilege,
decode(mod(oa.option$,2), 1, 'YES', 'NO') grantable,
ue.name grantee,
ur.name grantor,
u.name owner,
decode(o.TYPE#, 2, 'TABLE', 4, 'VIEW', 42, 'MATERIALIZED VIEW') object_type,
o.name object_name,
c.name column_name
from sys.objauth$ oa, sys.obj$ o, sys.user$ u, sys.user$ ur, sys.user$ ue,
sys.col$ c, table_privilege_map tpm
where oa.obj# = o.obj#
and oa.grantor# = ur.user#
and oa.grantee# = ue.user#
and oa.obj# = c.obj#
and oa.col# = c.col#
and bitand(c.property, 32) = 0 /* not hidden column */
and oa.col# is not null
and oa.privilege# = tpm.privilege
and u.user# = o.owner#
and o.TYPE# in (2, 4, 42)
and ue.name = 'your user'
and bitand (o.flags, 128) = 0;
这将列出您(指定)用户的所有对象授予(包括列授予)。如果您不希望获得列级授予,则删除以“ union”子句开头的select的所有部分。
UPD:研究文档后,我发现了另一个视图,该视图以更简单的方式列出了所有赠款:
select * from DBA_TAB_PRIVS where grantee = 'your user';
请记住,Oracle中没有 DBA_TAB_PRIVS_RECD视图。
我知道的最全面,最可靠的方法仍然是使用DBMS_METADATA:
select dbms_metadata.get_granted_ddl( 'SYSTEM_GRANT', :username ) from dual;
select dbms_metadata.get_granted_ddl( 'OBJECT_GRANT', :username ) from dual;
select dbms_metadata.get_granted_ddl( 'ROLE_GRANT', :username ) from dual;
有趣的答案。
select distinct 'GRANT '||privilege||' ON '||OWNER||'.'||TABLE_NAME||' TO '||RP.GRANTEE
from DBA_ROLE_PRIVS RP join ROLE_TAB_PRIVS RTP
on (RP.GRANTED_ROLE = RTP.role)
where (OWNER in ('YOUR USER') --Change User Name
OR RP.GRANTEE in ('YOUR USER')) --Change User Name
and RP.GRANTEE not in ('SYS', 'SYSTEM')
;
以下查询可用于获取一个用户的所有特权。仅在第一个查询中提供用户名,即可获得该用户的所有特权。
使用用户AS(选择“ SCHEMA_USER” usr FROM dual),使用角色AS(选择dmit_role FROM dba_role_privs rp JOIN用户ON rp.GRANTEE = users.usr UNION SELECT named_role FROM role_role_privs角色进入(选择dmit_role FROM dba_role_privs rp JOIN用户ON rp。 GRANTEE = users.usr)),tab_privilage AS(SELECT OWNER,TABLE_NAME,PRIVILEGE FROM role_tab_privs rtp JOIN角色r ON rtp.role = r.granted_role UNION SELECT OWNER,TABLE_NAME,PRIVILEGE FROM Dba_Tab_Privs dtp JOIN用户。 usr),sys_privileges AS(从dba_sys_privs dsp中选择特权,将用户加入dsp.grantee = users.usr)SELECT * FROM tab_privilage ORDER BY所有者,表名--SELECT * FROM sys_privileges