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

grant SELECT access to v$session to other users

我想在 Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

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

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

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

我收到这个错误:

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

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

SQL> grant select on v_$session to hr;

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

例如,IFH_OWNER 可以访问 v$session,用户 id854812 不能:

作为 id854812:

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

作为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;

作为 id854812:

select ifh_owner.getSessionCount from dual;
56