Oracle管理权限和角色--对象权限

127 阅读3分钟

开启掘金成长之旅!这是我参与「掘金日新计划 · 12 月更文挑战」的第29天,点击查看活动详情

10 数据库管理员

10.1 管理权限和角色

10.1.2 管理权限和角色--对象权限

·对象权限介绍

指访问其它方案对象的权利,用户可以直接访问自己方案的对象。但是如果要访别的方案的对象,则必须具有对象的权限。

比如smith用户要访问scott.emp表(scott:方案,emp:表),则必须在scott.emp表上具有对象的权限。

常用的有:

alter 修改 delete 删除 select 查询
insert 添加 update 修改 index  索引
references 引用 execute 执行
alter 修改表结构 update修改表数据

·显示对象权限

通过数据字段视图可以显示用户或是角色所具有的对象权限。视图为 dba_tab_privs

conn system/manager
select distinct privilege from dba_tab_privs;
select grantor,owner,table_name,privilege from dba_tab_privs where grantee='BLAKE';

·授予对象权限

在oracle9i前,授予对象权限是由对象的所有者来完成的,如果用其他的用户来操作,则需要用户具有相应的(with grant option)权限,从oracle9i开始,dba用户(sys,system)可以将任何对象上的对象权限授予其它用户,授予对象权限是用grant命令来完成的。

对象权限可以授予用户、角色和public,在授予权限时,如果带有with grant option选项,则可以将该权限转授给其它用户。但是要注意with grant option选项不能被授予角色。

1.monkey用户要操作scott.emp表,则必须授予相应的对象权限

(1)希望monkey可以查询scott.emp的表数据,怎样操作?

grant select on emp to monkey;
select * from scott.emp;

(2)希望monkey可以修改scott.emp的表数据,怎样操作?

grant update on emp to monkey;

(3)希望monkey可以删除scott.emp的表数据,怎样操作?

grant delete on emp to monkey;

(4)有没有更加简单的方法,一次把所有权限赋给monkey?

grant all on emp to monkey;

2.能否对monkey访问权限更加精细控制(授予列权限)

(1)希望monkey只可以修改scott.emp的表的sal字段,怎样操作?

grant update on emp(sal) to monkey

(2)希望monkey只可查询scott.emp的表的ename,sal数据,怎样操作?

grant select on emp(ename,sal) to monkey

3.授予alter权限

如果blake用户要修改scott.emp表的结构,则必须授予alter对象权限

conn scott/tigger
grant alter on emp to blake;

当然也可以用system,sys来完成这件事

4.授予execute权限

如果用户想要执行其它方案的包/过程/函数,则须有execute权限。

比如为了让ken可以执行包dbms.transaction,可以授execute权限

conn system/admin
grant execute on dbms.transaction to ken;

5.授予index权限

如果想在别的方案的表上建立索引,则必须具有index对象权限

如为了让blake可以在scott.emp上建立索引,就给其index的对象权限

conn scott/tigger
grant index on scott.emp to blake with grant option

6.使用with grant option选项

该选项用于转授对象权限,但是该选项只能被授予用户,而不能授予角色

conn scott/tigger
grant select on emp to blake with grant option
conn blake/shunping
grant select on scott.emp to jones

·回收对象权限

在oracle9i中,收回对象的权限可以由对象的所有者来完成,也可以用dba用户(sys,system)来完成。

这里要说明的是:收回对象权限后,用户就不能执行相应的sql命令,但是要注意的是对象的权限是否会被级联收回?-->[已被回收]

如:

scott ---------->blake--------->jones

select on emp select on emp select on emp
conn scott/tigger@orcl
revoke select on emp from blake