Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Kill all database sessions

Eslam_ElbyalyMar 7 2015 — edited Mar 9 2015

hi , i am using oracle 10g db , and i am trying to kill all sessions connected to the database with this code :

CREATE OR REPLACE PROCEDURE kill_sessions IS

begin    

    for x in ( 

            select Sid, Serial#, machine, program 

            from v$session 

            where 

                username <> 'the one i am connected to in order to kill sessions'

        ) loop 

        execute immediate 'Alter System Kill Session '''|| x.Sid 

                     || ',' || x.Serial# || ''' IMMEDIATE'; 

    end loop; 

end;

when i issue this code from a user which i granted the DBA privilege to him , i face these errors :

PL/SQL: SQL Statement ignored
PL/SQL: ORA-00942: table or view does not exist
PL/SQL: Statement ignored     -- for execute immediate
PLS-00364: loop index variable 'X' use is invalid

but when i log on with " sys as sysdba " , the procedure is created successfully without any errors .

do i miss something here ? do i need any other privileges other than the " DBA " one ?

thanks a lot

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 6 2015
Added on Mar 7 2015
8 comments
1,636 views