Oracle Privileges and Roles

本文详细介绍了Oracle数据库中的权限管理,包括系统权限与对象权限的区别,如何授予和撤销各种权限,如select、insert、update等,以及如何管理角色和使用公共权限。文章还提供了SQL语句示例,帮助读者理解权限的分配和回收。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

               

Oracle Privileges

Oracle包括两大类权限,一种是系统权限,另外一种是对象权限。

System Privileges
  • Create session
  • Create table
  • Create view
  • Create procedure
  • Sysdba
  • Sysoper
Object Privileges  Privileges can be assigned to any of the following types of database objects:
  • Tables: all, alter, debug, delete, flashback, insert, on commit refresh, query rewrite, references, select, update
  • Views: debug, delete, insert, flashback, references, select, under, update
  • Sequence: alter, select
  • Packages, Procedures, Functions: debug, execute
  • Materialized Views: delete, flashback, insert, select, update
  • Directories: read, write
  • Libraries: execute
  • User Defined Types: debug, execute, under
  • Operators: execute
  • Indextypes: execute


Privileges Tables/Views

System PrivilegesDBA_SYS_PRIVS

Object Privileges: DBA_TAB_PRIVS
Data Dictionary Objects Related To Object Privileges                                                                                                                                                                                                                                                                                                                             
objauth$objpriv$       
dba_col_privsall_col_privsuser_col_privs
-all_col_privs_madeuser_col_privs_made
-all_col_privs_recduser_col_privs_recd
dba_tab_privsall_tab_privsuser_tab_privs
-all_tab_privs_madeuser_tab_privs_made
-all_tab_privs_recduser_tab_privs_recd
   
column_privilegestable_privilegestable_privilege_map

Roles granted to users or roles  :   DBA_ROLE_PRIVS 

上述三表为DBA_表,普通用户可以使用下边的三张表
SELECT * FROM USER_SYS_PRIVS;  
SELECT * FROM USER_TAB_PRIVS;
SELECT * FROM USER_ROLE_PRIVS;

List Privileges

列出其他用户授权给当前用户的表权限
SELECT * FROM USER_TAB_PRIVS_RECD;

查当前用户的角色
select * from user_role_privs;

查自己拥有哪些系统权限
select * from session_privs;

列出当前用户授权给其他用户的表权限
SELECT * FROM USER_TAB_PRIVS_MADE;

Grant Privileges on Tables


PrivilegeDescription
SelectAbility to query the table with a select statement.
InsertAbility to add new rows to the table with the insert statement.
UpdateAbility to update rows in the table with the update statement.
DeleteAbility to delete rows from the table with the delete statement.
ReferencesAbility to create a constraint that refers to the table.
AlterAbility to change the table definition with the alter table statement.
IndexAbility to create an index on the table with the create index statement.

语法:

grant privileges on object to user;
比如:如果你想把suppliers表的查询,插入,修改,删除的权限付给用户smithj,你可以执行下边的语句
grant select, insert, update, delete on suppliers to smithj;
你也可以直接使用 all关键字来赋权,表示你想把对象所有的权限付给某个用户,比如:
grant all on suppliers to smithj;
如果你想让所有用户都可以查询某张表,那你可以使用public关键字,比如:
grant select on suppliers to public;

Revoke Privileges on Tables


授权(Grant)之后,你想取消授权,那就得revoke了。

语法:

revoke privileges on object from user;
比如,你想取消anderson删除supplier表的权利,可以执行:
revoke delete on suppliers from anderson;
你想取消anderson针对supplier表的所有权利,可以执行:
revoke all on suppliers from anderson;

如果你有授权给public(所有用户),现在想撤权,可以执行:

revoke all on suppliers from public;

   

Grant Privileges on Functions/Procedures

针对Functions/Procedures的授权。
Functions/Procedures的权限类别
PrivilegeDescription
ExecuteAbility to compile the function/procedure.Ability to execute the function/procedure directly.

语法:

grant execute on object to user;
把Funciton Find_Value的执行权限付给用户smithj,可以执行:

grant execute on Find_Value to smithj;
把Funciton Find_Value的执行权限付给所有用户,可以执行:
grant execute on Find_Value to public;

Revoke Privileges on Functions/Procedures

针对Functions/Procedures的撤权。

语法:

revoke execute on object from user;

撤销anderson针对Find_Value Funciton的执行权限,可以执行:

revoke execute on Find_Value from anderson;
如果你赋权过所有用户,现在想撤销,可以执行:
revoke execute on Find_Value from public;

  

Roles

角色(Role)是一系列权限的集合,通过权限可以大大简化权限的授予和回收工作。通常创建一个用户之后,我们授予用户两个角色就足够使用了,这两个角色是CONNECT和RESOURCE。
SQL> select * from DBA_SYS_PRIVS where grantee = 'CONNECT';
GRANTEE                        PRIVILEGE                                ADMIN_OPTION
------------------------------ ---------------------------------------- ------------
CONNECT                        CREATE SESSION                           NO

SQL> select * from DBA_SYS_PRIVS where grantee = 'RESOURCE';
GRANTEE                        PRIVILEGE                                ADMIN_OPTION
------------------------------ ---------------------------------------- ------------
RESOURCE                       CREATE TRIGGER                           NO
RESOURCE                       CREATE SEQUENCE                          NO
RESOURCE                       CREATE TYPE                              NO
RESOURCE                       CREATE PROCEDURE                         NO
RESOURCE                       CREATE CLUSTER                           NO
RESOURCE                       CREATE OPERATOR                          NO
RESOURCE                       CREATE INDEXTYPE                         NO
RESOURCE                       CREATE TABLE                             NO
8 rows selected
SQL> 


创建一个可以访问数据库的用户,大体步骤:
SQL> create user tianpan identified by welcome
  2  default tablespace users
  3  temporary tablespace temp;
User created

SQL> select * from dba_sys_privs where grantee = 'TIANPAN';
GRANTEE                        PRIVILEGE                                ADMIN_OPTION
------------------------------ ---------------------------------------- ------------

SQL> grant connect,resource to tianpan;
Grant succeeded

SQL> select * from dba_sys_privs where grantee = 'TIANPAN';
GRANTEE                        PRIVILEGE                                ADMIN_OPTION
------------------------------ ---------------------------------------- ------------
TIANPAN                        UNLIMITED TABLESPACE                     NO

SQL> conn tianpan/welcome
Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 
Connected as tianpan

SQL> create table test_priv (name varchar2(10));
Table created

转载请注明出处:http://blog.youkuaiyun.com/pan_tian/article/details/11763889


           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.youkuaiyun.com/jiangjunshow

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值