oracle 向其他用户授予对 v$session 的 SELECT 访问权限

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46562257/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:28:03  来源:igfitidea点击:

grant SELECT access to v$session to other users

oracleoracle11gr2

提问by en Lopes

I want to grant SELECT access to v$session to other users in an Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

我想将 v$session 的 SELECT 访问权限授予其他用户 Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

but when I run this query:

但是当我运行这个查询时:

SELECT owner, object_type FROM dba_objects WHERE object_name = 'V$SESSION';

I got this error:

我收到此错误:

00942. 00000 -  "table or view does not exist"

回答by Cyrille MODIANO

Oracle v$ views are named V_$VIEWNAME and they have synonyms in format V$VIEWNAME and you can't give privilege on a synonym. If you want to give permission to a V$ view you must give it like below

Oracle v$ 视图被命名为 V_$VIEWNAME 并且它们具有格式为 V$VIEWNAME 的同义词,您不能对同义词授予特权。如果你想授予 V$ 视图的权限,你必须像下面这样授予它

SQL> grant select on v_$session to hr;

回答by Steef

We also needed a regular user without access to v$session to cleanup sessions. A function will execute with the privileges of the owning schema, so if you create a function as the user having access to V$SESSION you can execute it from the user not having the required privilege.

我们还需要一个无法访问 v$session 的普通用户来清理会话。函数将使用拥有架构的权限执行,因此如果您以有权访问 V$SESSION 的用户身份创建函数,您可以从没有所需权限的用户那里执行它。

For example, IFH_OWNER has access to v$session, user id854812 doesn't:

例如,IFH_OWNER 有权访问 v$session,用户 id854812 没有:

As id854812:

如 id854812:

select count(*) from v$session
ORA-00942: table or view does not exist

As IFH_OWNER:

作为 IFH_OWNER:

select count(*) from v$session
56

create or replace function getSessionCount return int
as
  vCnt int;
begin
  select count(*) into vCnt from v$session;
  return( vCnt);
end;

select getSessionCount from dual;
56

grant execute on getSessionCount to id854812;

As id854812:

如 id854812:

select ifh_owner.getSessionCount from dual;
56