1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Oracle】オブジェクト権限の数を権限の種類ごとにカウントする【SQL*Plus】

Last updated at Posted at 2022-08-03

where句の後は適宜変更。
tp.OWNER = 'OWN_USER'
tp.GRANTEE = 'GRA_USER'
OWN_USERが付与元(テーブル所有者)、GRA_USERが付与先です。
ob.OBJECT_TYPE = 'TABLE'
オブジェクトタイプ指定はあったほうが便利なので。
(例えば、全テーブルに権限付与するとき、dba_tablesからcount(*)したものと一致してるか、みたいな使い方)

col ~~~ for a20a20は文字数に合わせて変えます。

set lin 300
set pages 300
col owner for a20
col grantee for a20
col privilege for a20
col object_type for a20

select tp.OWNER,tp.GRANTEE,ob.OBJECT_TYPE,tp.PRIVILEGE,count(*)
from dba_tab_privs tp 
inner join
dba_objects ob on
tp.TABLE_NAME = ob.OBJECT_NAME and
tp.OWNER = ob.OWNER
where
tp.OWNER = 'OWN_USER' and
tp.GRANTEE = 'GRA_USER' and
ob.OBJECT_TYPE = 'TABLE'
group by tp.OWNER,tp.GRANTEE,ob.OBJECT_TYPE,tp.PRIVILEGE
order by 1,2,3,4;

実行例サンプル。

OWNER                GRANTEE              OBJECT_TYPE          PRIVILEGE              COUNT(*)
-------------------- -------------------- -------------------- -------------------- ----------
OWN_USER             GRA_USER             TABLE                DELETE                       10
OWN_USER             GRA_USER             TABLE                INSERT                       10
OWN_USER             GRA_USER             TABLE                SELECT                       10
OWN_USER             GRA_USER             TABLE                UPDATE                       10
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?