Solved

Execute immediate problem

Posted on 2007-11-28
2
1,145 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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

920 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

16 Experts available now in Live!

Get 1:1 Help Now