このスクリプトは、ロールに付与されたすべてのテーブル特権のリストを生成します...
select 'grant '||privilege||' on '||owner||'.'||table_name||' to '||grantee
||case when grantable = 'YES' then ' with grant option' else null end
||';'
from dba_tab_privs
where owner in ('A', 'B')
and grantee in ( select role from dba_roles )
order by grantee, owner
/
あなたの質問はその点があいまいであるため、被付与者の役割を制限していないことに注意してください。の sub_query にフィルターを追加する必要がある場合がありますdba_roles
。他のロールに付与されたロールがある場合は、それらも取得する必要があります...
select 'grant '||granted_role||' to '||grantee
||case when admin_option = 'YES' then ' with admin option' else null end
||';'
from dba_role_privs
where grantee in ( select role from dba_roles )
order by grantee, granted_role
/
ロールのリストを取得するには ...
select 'create role '||role ||';'
from dba_roles
where role like '%PROXY'
/
これらのスクリプトは、システム権限の付与を生成しないことに注意してください。また、ディレクトリオブジェクトを使用すると、追加のキーワードが必要になるため、生活は少し複雑になります...
select 'grant '||privilege||' on '||owner||'.'||table_name||' to '||grantee
||case when grantable = 'YES' then ' with grant option' else null end
||';'
from dba_tab_privs
where owner in ('A', 'B')
and grantee in ( select role from dba_roles )
and table_name not in ( select directory_name from dba_directories )
union all
select 'grant '||privilege||' on directory '||table_name||' to '||grantee
||case when grantable = 'YES' then ' with grant option' else null end
||';'
from dba_tab_privs
where grantee in ( select role from dba_roles )
and table_name in ( select directory_name from dba_directories )
/
編集
9i では、Oracle は DBMS_METADATA パッケージを導入しました。これは、これらの種類のクエリの多くを単純な PL/SQL API にまとめたものです。たとえば、この呼び出しは、A に付与されたすべてのオブジェクト権限を持つ CLOB を生成します ...
select dbms_metadata.get_granted_ddl('OBJECT_GRANT', 'A') from dual
/
これは明らかに、自分で作成するよりもはるかに簡単です。