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 6796097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:25:34+00:00 2026-05-26T18:25:34+00:00

I have the following PL/SQL being sent to a remote oracle 11gr2 server via

  • 0

I have the following PL/SQL being sent to a remote oracle 11gr2 server via ADO.
It’s purpose is to check whether a user exists. Then if it does, kill of all its connections. Finally it drops the user.

DECLARE   
   i INTEGER;  
BEGIN  
   select count(1) into i from dba_users where username='<schema>';
   if i=0 THEN 
     FOR c IN (SELECT s.sid,s.serial# FROM v$session s WHERE s.username = '<schema>') LOOP    
       EXECUTE IMMEDIATE 'alter system kill session ''' ||c.sid || ',' || c.serial# || '''';  
     END LOOP;   
     drop user <schema> Cascade;   
   END IF;  
END;

The error message I have received after much tweaking is still:

ERROR:[Microsoft][ODBC driver for Oracle][Oracle]ORA-06550: line 1,
column 286: PLS-00103: Encountered the symbol “DROP” when expecting
one of the following:

( begin case declare else elsif end exit for goto if loop mod
null pragma raise return select update while with
<<
continue close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe purge

It doesn’t like the syntax of having the drop inside of the IF statement. Does anyone know who to make this run properly?

EDIT:
To be clear, I would normally never execute this statement in this manner. But due to the environment, it is the only possible way and is not creating any security risks. I know I’m violating nearly every good practice, but it is necessary this time!

  • 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-26T18:25:35+00:00Added an answer on May 26, 2026 at 6:25 pm

    You cannot issue DDL (i.e. DROP) statements directly in PL/SQL you’ll need to run your DROP statement using dynamic SQL.

    The easiest way to achieve this is with the EXECUTE IMMEDIATE statement (in a similar way to how you have already used it for the ALTER SESSION command):
    http://download.oracle.com/docs/cd/B12037_01/appdev.101/b10807/13_elems017.htm

    DECLARE
       i INTEGER;
    BEGIN
       SELECT COUNT( 1 )
         INTO i
         FROM dba_users
        WHERE username = '<schema>';
    
       IF i = 0
       THEN
          FOR c IN ( SELECT s.sid,
                            s.serial#
                       FROM v$session s
                      WHERE s.username = '<schema>' )
          LOOP
             EXECUTE IMMEDIATE 'alter system kill session ''' || 
                               c.sid || ',' || c.serial# || '''';
          END LOOP;
    
          EXECUTE IMMEDIATE 'DROP USER :username CASCADE'
          USING '<schema>';   
       END IF;
    END;
    

    Incidentally, you might want to look into using bind variables instead of concatenating the values in your dynamic SQL as it improves performance, especially in a loop.

    e.g.

    EXECUTE IMMEDIATE 'alter system kill session '':sid'','':serial'''
    USING c.sid,
          c.serial#;
    

    Hope it helps…

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

Sidebar

Related Questions

I have the following sql being run on an Oracle 10g database: select /*+
Imagine I have the following SELECT statement in a view (SQL Server 2008): SELECT
I have an interesting case of results sets returned by SQL Server being different
I have the following code. In SQL Server profiler I can see the insert
We have the following simple Stored Procedure that runs as an overnight SQL server
I have the following parameter being bound for calling a SQL procedure: TCHAR str[41];
I have been using the following SQL to create a user, login and database.
i have following sql which gives me a report of dossiers being handled by
I have the following SQL-statement: SELECT DISTINCT name FROM log WHERE NOT name =
I have the following sql query for transforming data but is it possible to

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.