日期:2014-05-16  浏览次数:20326 次

建立视图时引用其他用户下的表出错

以用户user1登录,在自己的模式下建立视图v1,引用user2下的表t1: create view v1 as select * from user2.t1;
? ?提示错误:表或视图不存在。
? ?单独执行 select * from user2.t1; 可以查询出结果,说明该表存在且有权限访问。
? ?user1具有connect、resource、dba的权限。

?

user1能够 select * from user2.t1 是因为它有select from any table 的system privilege。 而
要create view as select from user2.t1 则看来是需要有object privilege. 这个就是能用user2来
grant select on t1 to user1才能做到。 然后create view就可以成功。

?

select any table 的权限不就包括了select on user2.t1吗?
user1的select any table权限是通过dba角色授予的,我知道通过角色授予的权限在存储过程中无效,是不是在创建视图时也无效呢?

?

"是不是在创建视图时也无效呢"
是的!
你可以看SQL REFERENCE之CREATE VIEW
The owner of the schema containing the view must have the privileges necessary to
either select, insert, update, or delete rows from all the tables or views on which the
view is based. The owner must be granted these privileges directly, rather than
through a role.