Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7509947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:04:38+00:00 2026-05-29T23:04:38+00:00

How to modify this procedure to let it use bind variables PROCEDURE KILL(user IN

  • 0

How to modify this procedure to let it use bind variables

PROCEDURE KILL(user IN VARCHAR2) AS
BEGIN
  FOR REC IN (SELECT sid,serial# serial FROM V$SESSION WHERE username = user)
  LOOP 
    execute immediate 'alter system kill session '' :1 , :2 '' immediate' 
    using rec.sid,  rec.serial; 
    END LOOP; 
END; 

It gives:

bind variable does not exist

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T23:04:39+00:00Added an answer on May 29, 2026 at 11:04 pm

    The bind variables in your statement are being treated as literal strings rather than place holders. If you output the statement you’re generating:

    BEGIN
        FOR REC IN (SELECT sid,serial# serial FROM V$SESSION WHERE username = user)
        LOOP
            dbms_output.put_line('alter system kill session '':1,:2'' immediate');
        END LOOP;
    END;
    /
    

    … you see lines like:

    alter system kill session ':1,:2' immediate
    

    The ':1,:2' is treated as a static value and not as two bind variables. You can’t use bind variables in dynamic DDL, and I’m not sure if that applies to alter commands, so this may be impossible anyway.

    The simplest way to achieve this may be to generate the whole statement in the cursor:

    BEGIN
        FOR REC IN (
            SELECT 'alter system kill session ''' || sid ||','|| serial#
                ||''' immediate' stmt
            FROM V$SESSION WHERE username = user)
        LOOP
            dbms_output.put_line(rec.stmt);
            --execute immediate rec.stmt;
        END LOOP;
    END;
    /
    

    With the execute commented out (I don’t really want to kill my sessions just now) you can just see the commands it will run, like:

    alter system kill session '58,47157' immediate
    

    Your approach may still be flawed though as it will kill the session that is executing the block, and it may or may not kill it last. I think this is in the realms of undefined behaviour, and I don’t really want to try it to find out what happens… I doubt that’s what you actually want anyway.

    Edit: ‘flawed’ comment was based on using user, which in my anonymous block would be the executing user; in your proc it would be the user from the parameter. Using a keyword as a parameter name is confusing though, so I’d recommend changing the name to something like p_user, in the args and the statement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am essentially attempting to modify this stored procedure. Modified stored procedure: CREATE PROCEDURE
I have this script: select name,create_date,modify_date from sys.procedures order by modify_date desc I can
How can I modify this: /services/type/single_dwelling/ to this: /ajax/services/single_dwelling/development Currently I have: linkUrl =
I'm trying to modify this: jquery desktop by adding a input field inside one
I am looking to modify this php code to do a recursive search for
Is there an easy way to modify this code so that the target URL
Is there anyway I can modify this code example #include <stdlib.h> #include <iostream> class
I found this PHP code in an app I have to modify... $links =
I'm trying to modify the code from this script . Basically I'm trying to
This week I have figured out how to modify form elements in the location

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.