Oracle收集使用者的許可權

2021-12-30 02:26:59 字數 2306 閱讀 5368

oracle收集使用者的許可權

【使用場景】系統上線前準備工作。一般遷移資料的時候經常使用匯入dump檔案的方法。由於是乙個乙個使用者匯入進去的,所以在匯入過程中會報許可權問題的錯誤(可以忽略),還必須在生產庫授權系統才能正常工作。使用下面的指令碼可以得到授權語句。

在uat環境執行select語句,在生產環境執行grant語句,根據實際使用者做相應的修改。

注意:查詢的使用者需要有檢視dba_開頭資料字典的許可權,否則報出表或者檢視不存在。

select 'grant ' || t1.granted_role || ' to ' || t1.grantee || ';' as text

from dba_role_privs t1

where t1.grantee in ('aboq',

'amlm',

'bop',

'credit',

'datacore',

'mdr2',

'metabase',

'metabase_credit',

'report',

'uprr',

'work')

union all

select 'grant ' || t2.privilege || ' to ' || t2.grantee || ';' as text

from dba_sys_privs t2

where t2.grantee in ('aboq',

'amlm',

'bop',

'credit',

'datacore',

'mdr2',

'metabase',

'metabase_credit',

'report',

'uprr',

'work')

union all

select 'grant ' || t3.privilege || ' on ' || t3.owner || '.' ||

t3.table_name || ' to ' || t3.grantee || ';' as text

from dba_tab_privs t3

where t3.grantee in ('aboq',

'amlm',

'bop',

'credit',

'datacore',

'mdr2',

'metabase',

'metabase_credit',

'report',

'uprr',

'work');

這樣寫比較死板,使用『&』替換變數也很不好用,可以建立乙個儲存過程。

create or replace procedure user_priv(username in varchar2) as

cursor v_cur is

select 'grant ' || t1.granted_role || ' to ' || t1.grantee || ';' as text

from dba_role_privs t1

where t1.grantee = upper(username)

union all

select 'grant ' || t2.privilege || ' to ' || t2.grantee || ';' as text

from dba_sys_privs t2

where t2.grantee = upper(username)

union all

select 'grant ' || t3.privilege || ' on ' || t3.owner || '.' ||

t3.table_name || ' to ' || t3.grantee || ';' as text

from dba_tab_privs t3

where t3.grantee = upper(username);

/*select privilege from dba_sys_privs where grantee in (select granted_role from dba_role_privs where grantee=upper(username) );如果有必要可-以收集角色中的許可權*/

begin

for v_t in v_cur loop

begin

dbms_output.put_line(v_t.text);

end;

end loop;

end;

最後直接執行procedure即可 execute user_priv (username => 'hr');

oracle使用者的許可權

dba 擁有全部特權,是系統最高許可權,只有dba才可以建立資料庫結構。resource 擁有resource許可權的使用者只可以建立實體,不可以建立資料庫結構。connect 擁有connect許可權的使用者只可以登入oracle,不可以建立實體,不可以建立資料庫構。對於普通使用者 授予conne...

Oracle 使用者許可權

sys 系統管理員,擁有最高許可權 system 本地管理員,次高許可權 scott 普通使用者,密碼預設為tiger,預設未解鎖 sys 系統管理員,擁有最高許可權 system 本地管理員,次高許可權 scott 普通使用者,密碼預設為tiger,預設未解鎖 二 登陸 sqlplus as sy...

Oracle使用者許可權

系統許可權 1 使用grant語句向使用者賦予系統許可權 grant system privilege to user name with admin option 注 使用with admin option語句後,使使用者可以將相同許可權賦給其他使用者。2 使用revoke語句撤銷系統許可權 re...