Solved

Execute immediate problem

Posted on 2007-11-28
2
1,140 Views
Last Modified: 2013-12-07
I got this code yesterday to track and kill TOAD sessions:
BEGIN
    FOR s IN (SELECT SID, serial#
                FROM v$session
               WHERE program LIKE '%TOAD%')
    LOOP
        EXECUTE IMMEDIATE 'alter system kill session ''' || TO_CHAR(s.SID) || ', ' || TO_CHAR(s.serial#)
                          || '''';
    END LOOP;
END;


It picks up the session, but the execute immediate does not successfully kill the session although the pl/sql completes successfully.  Within that code structure what modification do i need to make it work?
0
Comment
Question by:xoxomos
2 Comments
 
LVL 18

Accepted Solution

by:
Jinesh Kamdar earned 250 total points
ID: 20367231
Include immediate keyword. Trap the exception to show the error, if any.
BEGIN
 

FOR s IN (SELECT SID, serial# FROM v$session WHERE program LIKE '%TOAD%') LOOP

    EXECUTE IMMEDIATE 'alter system kill session ''' || TO_CHAR(s.SID) || ', ' || TO_CHAR(s.serial#) || ''' IMMEDIATE';

END LOOP;
 

EXCEPTION
 

WHEN OTHERS THEN

DBMS_OUTPUT.PUT_LINE(SQLCODE || ' - ' || SQLERRM);
 

END;

Open in new window

0
 

Author Comment

by:xoxomos
ID: 20367715
I saw that in the docs, but did not pay attention!!!
Thanks.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now