views:

608

answers:

7

Through a faulty script I have created a user with single quotes around his username (i.e. his username is 'username', not username) on an Oracle 9i system. Now I want to remove that user. Neither "DROP USER 'username'" nor "DROP USER \'username\'" nor "DROP USER (SELECT username FROM all_users where user_id = 123)" worked. How do I get rid of that user?

+4  A: 
create user "'bla'" identified by bla;

drop user "'bla'";
Jeffrey Kemp
This doesn't work for me:SQL> DROP USER "'username'" CASCADE;DROP USER "'username'" CASCADE*ERROR at line 1:ORA-00604: error occurred at recursive SQL level 1ORA-00933: SQL command not properly ended ORA-06512: at line 7
Thomas Lötzer
Works for me. Tested on Oracle 11g though. SQL> create user "'username'" identified by bla; User created. SQL> drop user "'username'"; User dropped.
Jeffrey Kemp
You got a recursive SQL error - just guessing, maybe it has something to do with an object owned by the user? Not sure. What happens if you don't specify the CASCADE option?
Jeffrey Kemp
same error message
Thomas Lötzer
Jeffrey Kemp
The ORA-00933 might indicate a bug somewhere - when it cascades the drop to other objects or references, the code cannot cope with a username with quotes in it. This is just a guess. You may need to set trace on the session to see what recursive SQL is being run.
Jeffrey Kemp
Jeffrey Kemp
A comment in this thread: http://kr.forums.oracle.com/forums/thread.jspa?threadID=662605 leads me to ask, are there any system triggers enabled in your database (possibly to do with replication)?
Jeffrey Kemp
A: 

I don't know Oracle off-hand, but might you try enclosing it in double quotes?

(I'll delete this answer if its wrong)

Chacha102
+1  A: 

Try DROP USER "'username'" or DROP USER ''username''. (Note that those last quotes are all single quotes)

Brian Ramsay
the first idea is correct (double quotes), the second (single quotes) won't work (I was wondering that myself and tried it)
Jeffrey Kemp
+2  A: 

According to Oracle's Documentation...

"A quoted identifier begins and ends with double quotation marks ("). If you name a schema object using a quoted identifier, then you must use the double quotation marks whenever you refer to that object."

So this...

DROP USER "username" CASCADE;
CptSkippy
A: 

I know this is an old post, but for anyone stumbling across this as the result of a search on this problem - the issue appears to be that a database trigger is firing on drop user. I've posted the solution I found for Oracle XE ( probably the same for other 10g releases) here

Hope someone finds this useful,

Mike

Mike Smithers
A: 

The following code might help you :

declare

sel_username varchar2(30); r_user_id varchar2(30); r_username varchar2(30); user_cmd varchar2(200);

BEGIN /* This procedure will delete a single user_id and can be used to delete a user with none displayable characters in the name

Replace the user_id in this script to that you want to delete !!

Author: Ulrich Henkenjohann - March 2010 / tested on ORACLE 10.2.0.4

*/
-- select the username for a special user_id. Ther username may contain none displayed characters

select username into sel_username from dba_users where user_id = 34; select user_id, username into r_user_id , r_username from dba_users where username = sel_username ; DBMS_OUTPUT.PUT_LINE('Selected user: ' || r_user_id || ' ' || r_username);

-- If a test is needed, an alter passwort command may be usefull -- user_cmd := 'ALTER USER "' || r_username || '" IDENTIFIED BY PASSWORDX ';

-- Drop the selected user

user_cmd := 'DROP USER "' || r_username || '" CASCADE '; DBMS_OUTPUT.PUT_LINE('Executing user_cmd: ' || user_cmd ); execute immediate user_cmd ;

END; /

Ulrich
A: 

Once again with better format:

declare

sel_username varchar2(30);

r_user_id varchar2(30);

r_username varchar2(30);

user_cmd varchar2(200);

BEGIN /*

This procedure will delete a single userid and can be used to delete a user with none displayable characters in the name

Replace the user_id in this script !!

Author: Ulrich Henkenjohann - March 2010 / tested on ORACLE 10.2.0.4

*/
-- select the username for a special user_id. Ther username may contain none displayed characters

select username into sel_username from dba_users where user_id = 34;

select user_id, username into r_user_id , r_username from dba_users where username = sel_username ;

DBMS_OUTPUT.PUT_LINE('Selected user: ' || r_user_id || ' ' || r_username);

-- If a test is needed, an alter passwort command may be usefull

-- user_cmd := 'ALTER USER "' || r_username || '" IDENTIFIED BY PASSWORDX ';

-- Drop the selected user

user_cmd := 'DROP USER "' || r_username || '" CASCADE ';

DBMS_OUTPUT.PUT_LINE('Executing user_cmd: ' || user_cmd );

execute immediate user_cmd ;

END; /

Ulrich