<!-- [if gte mso 9]><xml><w:WordDocument><w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel><w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery><w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery><w:DocumentKind>DocumentNotSpecified</w:DocumentKind><w:DrawingGridVerticalSpacing>7.8</w:DrawingGridVerticalSpacing><w:View>Normal</w:View><w:Compatibility></w:Compatibility><w:Zoom>0</w:Zoom></w:WordDocument></xml><![endif]-->
--============================
--author:_yeeXun
--date: 12/31/2010 11:05:00 AM
--address:Jau 17-304
--============================
对象权限 指访问其他方案的权利,用户直接访问自己的方案的对象,但是如果要访问别的方案的 对象,则必须具有对象的权限。
比如smith 用户要访问 scott.emp 表( scott :方案, emp :表),则不需再 scott.emp 表上具有对象的权限。
常用的对象权限:
Alter--修改 ( 修改表结构 )delete-- 删除
Select--查询 insert-- 添加
Update--修改 ( 更新数据 )index-- 索引
References--引用 execute-- 执行
显示对象权限
通过数据字典视图可以显示用户或角色所具有的对象权限:dba_tab_privs;
授予对象权限
在oracle9i 前,授予对象权限是由对象的所有者来完成的,如果用其他的用户来操 作,则需要用户具有相应的(withgrantoption) 权限,从 oracle9i 开始, dba 用户(sys,system) 可以将任何对象上的对象权限授予其他用户,授予对象权限是用 grant命令来完成的。
对象权限可以授予用户,角色,和public 。在授予权限时,如果带有 withgrant option选项,则可以将该权限转授给其他用户, 但是要注意withgrantoption 选项不能被授予角色。
小案例
1. monkey用户要操作 scott.emp 表,则必须授予相应的对象权限
a) 希望monkey 可以查询 scott.emp 的表数据,怎样操作?
首先建立一个monkey 用户
SQL>createusermonkeyidentifiedbym123;
Usercreated
给 monkey用户授权
SQL>grantcreatesessiontomonkey;
Grantsucceeded
可以查看 monkey用户具有连接数据库的权限
SQL>connmonkey/m123;
ConnectedtoOracleDatabase10gEnterpriseEditionRelease 10.2.0.1.0
Connectedasmonkey
用monkey用户查看scott方案的emp表,得到了失败的提示
SQL>select*fromscott.emp;
select*fromscott.emp
ORA-00942:表或视图不存在
连接到scott用户,让scott用户为monkey用户授权
SQL>connscott/tiger;
ConnectedtoOracleDatabase10gEnterpriseEditionRelease 10.2.0.1.0
Connectedasscott
SQL>grantselectonemptomonkey;
Grantsucceeded
下面就是我们想要的结果:
SQL>select*fromscott.emp;
EMPNOENAMEJOBMGRHIREDATESALCOMM DEPTNO
---------------------------------------------------------- ------
8881test用户MANAGER77822010-12-2123.0023.00 10
......
15rowsselected
b) 希望monkey 可以修改 scott.emp 表的数据,怎样操作?
Sql>Grantupdateonemptomonkey;
c) 希望monkey 可以删除 scott.emp 表的数据,怎样操作?
Sql>Grantdeleteonemptomonkey;
d)一次性将所有对 scott.emp 表的数据操作的权限授予 monkey
Sql>Grantallonmeptomonkey;
2. 能否对monkey 访问权限更加精细控制( 授予列权限 )
a) 希望monkey 只可以修改 scott.emp 表的 sal 字段,怎样操作?
Grantupdateonemp(sal)tomonkey;
b) 希望monkey 只可以查询 scott.emp 表的 ename , sal 数据,怎样操作?
Grantselectonemp(ename,sal)tomonkey;
3. 授予alter 权限
如果monkey 用户要修改 scott.emp 表的结构,则必须授予 alter 对象权限
Sql>connscott/tiger;
Sql>grantalteronemptomonkey;
当然也可以由sys,system 来完成此事。
4. 授予execute 权限
如果用户想要执行其他方案的包/ 过程 / 函数,则必须有 execute 权限。
比如为了让monkey 用户可以执行 dbms_transaction ,可以授 execute 权限
Sql>connsystem/manger;
Sql>grantexecuteondbms_transactiontomonkey;
5. 授予index 权限
如果想在别的方案的表上建立索引,则必须具有index 对象权限,如:为了让 monkey 用户可以子scott.emp 上建立索引,就给其 index 的对象权限
Sql>connscott/tiger;
Sql>grantindexonscott.emptomonkeywithgrantoption
6. 使用withgrantoption 选项
该选项用于转授对象权限,但是该选项只能被授予用户,而不能授予角色
Sql>connscott/tiger;
Sql>grantselectonemptomonkeywithgrantoption;
Sql>connmonkey/m123;
Sql>grantselectonscott.emptoanybody;
回收对象权限
在oracle9i 中,收回对象的权限可由对象的所有者来完成,也可以由 dba 用户 (sys,system)来完成。
注意:收回对象权限后,用户就不能执行相应的sql 命令, 对象权限可以级联回收。
语法:revoke 对象权限 on 对象 from 用户;
1. 定义
2. 对象权限有哪些
如何赋给对象权限
--the end--
本文详细介绍了Oracle中对象权限的概念、常用权限、如何授予和回收权限,并通过实例演示了如何具体操作。
812

被折叠的 条评论
为什么被折叠?



