ORA-00942 表或视图不存在 问题的解决

查杀系统死锁的sql,最近想改造成存储过程,如下:

CREATE OR REPLACE PROCEDURE HERO_KILLLOCKSESSION

 

(OUT_COUNT OUT NUMBER, OUT_CUR OUT ZHUOCAIDEV.FUXJPACKAGE.FUXJRESULTSET) IS

 

BEGIN

 

  SELECT COUNT(*)

   INTO OUT_COUNT

   FROM V$LOCKED_OBJECT L, DBA_OBJECTS B,V$SESSION X, V$PROCESS C

  WHERE B.OBJECT_ID = L.OBJECT_ID

    AND L.SESSION_ID = X.SID

    AND C.ADDR = X.PADDR;

 

  OPEN OUT_CUR FOR

   SELECT B.OWNER,

          B.OBJECT_NAME,

          L.SESSION_ID,

          X.SERIAL#,

          X.USERNAME,

          X.LOGON_TIME,

          L.LOCKED_MODE,

          'alter system kill session '''|| X.SID || ',' || X.SERIAL# || '''' KILLSQL,

          C.SPID AS OS_PROCESS_ID,

          C.PID,

          'ps -ef | grep ' || C.SPID AS CHECK_OS_PROCESS_COMMAND,

          'kill -9 ' || C.SPID AS KILL_OS_PROCESS_COMMAND

     FROM V$LOCKED_OBJECT L, DBA_OBJECTS B,V$SESSION X, V$PROCESS C

    WHERE B.OBJECT_ID = L.OBJECT_ID

      AND L.SESSION_ID = X.SID

      AND C.ADDR = X.PADDR

    ORDER BY X.LOGON_TIME ASC;

 

END;

在系统sys模式下可以正常运行,在zhuocaidev下面报ORA-00942 表或视图不存在

但在正常的SQL中是能够对V$LOCKED_OBJECT , DBA_OBJECTS , V$SESSION ,V$PROCESS进行访问的。猜测估计是权限问题,联想到运行statspack报告的perfstat用户没有此问题,查看下statspack的创建脚本,发现需要单独使用下面语句进行赋权:

 

 

grant select on V_$SESSION toscott;

以sys用户登录,执行如下授权语句:

grant select on SYS.V_$LOCKED_OBJECTTO zhuocaidev;
grant select on  SYS.DBA_OBJECTS TOzhuocaidev;
grant select on SYS.V_$SESSION  TOzhuocaidev;
grant select on SYS.V_$PROCESS TO zhuocaidev;

在以zhuocaidev登录,可以正常创建存储过程.

你可能感兴趣的:(ORA-00942 表或视图不存在 问题的解决)