昨天用户在给一个视图授权的时候出现报错“ora-01720:不存在的授权选项”,根据报错提示,这是一个权限的问题,通过在授权时增加with grant option解决。
2.1、准备三个用户
(1)hr :存在jobs表(2)scott :创建视图 hr_jobs,并授予 select 权限给 shen
(3)shen :无需任何操作
2.2、实验操作
hr用户操作:hr用户将jobs表的select权限授权给scott用户
sql> conn hr/hr
connected.
sql> grant select on hr.jobs to scott;
scott用户操作:scott用户将hr用户的表jobs创建名为hr_hobs的视图,并授权给shen用户,此时报错ora-01720。
sql> conn scott/tiger
connected.
sql> create or replace view hr_jobs as select t.job_id,t.job_title from hr.jobs t;
sql> grant select on hr_jobs to shen;
grant select on hr_jobs to shen
*
error at line 1:
ora-01720: grant option does not exist for ‘hr.jobs’
sql> conn hr/hr
connected.
sql> grant select on hr.jobs to scott with grant option;
grant succeeded.
sql> conn scott/tiger
connected.
sql> grant select on hr_jobs to shen;
grant succeeded.
举个例子,我有一台笔记本电脑,我授权给张三使用(select权限),张三却想把我笔记本电脑卖掉(明显行不通,需要笔记本电脑的主人授权才行)。即我拥有该对象的"select"权限,但我没有 ‘支配’ 该对象的权限(with grant option)
select (case
when t.type = ‘view’ then
'grant select on ’ || t.owner || ‘.’ ||
t.referenced_name || ’ with grant select;’
else
'grant execute on ’ || t.owner || ‘.’ ||
t.name || ’ with grant select;’
end)
from all_dependencies t
where t.owner = ‘scott’
and t.name = ‘hr_jobs’
and t.type in (‘view’, ‘procedure’, ‘function’, ‘package body’);