使用grant命令将角色授予用户或其他的角色。
如下:
SQL> grant create session,create table,create view to clerk;
Grant succeeded.
SQL> grant select any table,clerk to manager;
Grant succeeded.
查询一下:
SQL> select * from role_sys_privs
2 where role in('CLERK','MANAGER','SALES');
ROLE PRIVILEGE ADM
------------------------------ --------------- ---
CLERK CREATE TABLE NO
CLERK CREATE VIEW NO
CLERK CREATE SESSION NO
MANAGER SELECT ANY TABL NO
E
SQL> select * from dba_role_privs
2 where granted_role like 'CL%';
GRANTEE GRANTED_ROLE ADM DEF
---------- ------------------------------ --- ---
MANAGER CLERK NO YES
SYSTEM CLERK YES YES
将角色授给用户:
SQL> grant manager to cat with admin option;
Grant succeeded.
SQL> conn cat/miaomiao
Connected.
SQL> select * from user_role_privs;
USERNAME GRANTED_ROLE ADM DEF OS_
------------------------------ ------------------------------ --- --- ---
CAT MANAGER YES YES NO
SQL> select * from session_privs;
PRIVILEGE
---------------
CREATE SESSION
CREATE TABLE
SELECT ANY TABL
E
CREATE VIEW
获取用户的系统权限
如下:
SQL> grant create session,create table,create view to clerk;
Grant succeeded.
SQL> grant select any table,clerk to manager;
Grant succeeded.
查询一下:
SQL> select * from role_sys_privs
2 where role in('CLERK','MANAGER','SALES');
ROLE PRIVILEGE ADM
------------------------------ --------------- ---
CLERK CREATE TABLE NO
CLERK CREATE VIEW NO
CLERK CREATE SESSION NO
MANAGER SELECT ANY TABL NO
E
SQL> select * from dba_role_privs
2 where granted_role like 'CL%';
GRANTEE GRANTED_ROLE ADM DEF
---------- ------------------------------ --- ---
MANAGER CLERK NO YES
SYSTEM CLERK YES YES
将角色授给用户:
SQL> grant manager to cat with admin option;
Grant succeeded.
SQL> conn cat/miaomiao
Connected.
SQL> select * from user_role_privs;
USERNAME GRANTED_ROLE ADM DEF OS_
------------------------------ ------------------------------ --- --- ---
CAT MANAGER YES YES NO
SQL> select * from session_privs;
PRIVILEGE
---------------
CREATE SESSION
CREATE TABLE
SELECT ANY TABL
E
CREATE VIEW
获取用户的系统权限