Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Execute immediate problem

Posted on 2007-11-28
2
Medium Priority
?
1,178 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 1000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
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…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Via a live example, show how to take different types of Oracle backups using RMAN.

963 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