Skip to Main Content
  • Questions
  • Procedure not allowing me to select V$Session table in procedure

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Ashwini.

Asked: May 25, 2020 - 9:07 am UTC

Last updated: May 26, 2020 - 5:44 am UTC

Version: 18.3

Viewed 1000+ times

You Asked

Hi Tom,

I have created the below procedure having SYS privilege.

CREATE OR REPLACE PROCEDURE kill_inactive_sessions AS
BEGIN
FOR inact_sess IN (
SELECT
sid,
serial#
FROM
v$session
WHERE
status = 'INACTIVE'
AND username = 'ASHWINI'
AND last_call_et >= 10800
) LOOP
EXECUTE IMMEDIATE 'ALTER SYSTEM KILL SESSION "'
|| inact_sess.sid
|| ','
|| inact_sess.serial#
|| '"';
END LOOP;
END;

Its giving me error in line 3 that table does not exists.

PL/SQL: SQL Statement ignored
PL/SQL: ORA-00942: table or view does not exist

Please help me.

and Connor said...

The owner of the procedure needs either: SELECT ANY DICTIONARY (which is a big big privilege to grant), or you can do as SYS:

grant select on V_$SESSION to [owner]


Note the underscore.

Is this answer out of date? If it is, please let us know via a Comment

More to Explore

Security

All of the vital components for a secure database are covered in the Security guide.