【问题标题】:Delete an oracle-user with single quotes in the username删除用户名中带单引号的 oracle-user
【发布时间】:2009-07-22 14:49:05
【问题描述】:

通过一个错误的脚本,我在 Oracle 9i 系统上创建了一个用单引号括住他的用户名的用户(即他的用户名是“用户名”,而不是用户名)。现在我想删除该用户。 "DROP USER 'username'" 和 "DROP USER \'username\'" 和 "DROP USER (SELECT username FROM all_users where user_id = 123)" 都不起作用。如何摆脱该用户?

【问题讨论】:

  • 不要忘记大小写

标签: oracle oracle9i


【解决方案1】:
create user "'bla'" identified by bla;

drop user "'bla'";

【讨论】:

  • 这对我不起作用:SQL> DROP USER "'username'" CASCADE; DROP USER "'username'" CASCADE * ERROR at line 1: ORA-00604: error occurred at recursive SQL level 1 ORA-00933: SQL command not properly end ORA-06512: at line 7
  • 为我工作。虽然在 Oracle 11g 上测试过。 SQL> 创建由 bla 标识的用户“'username'”;用户创建。 SQL> 删除用户“'用户名'”;用户已删除。
  • 您遇到了递归 SQL 错误 - 只是猜测,也许它与用户拥有的对象有关?没有把握。如果不指定 CASCADE 选项会怎样?
  • 好的。您是否使用 SYSDBA 角色登录?另外,请查看此链接:forums.oracle.com/forums/…
  • ORA-00933 可能表明某处存在错误 - 当它将 drop 级联到其他对象或引用时,代码无法处理带有引号的用户名。这只是一个猜测。您可能需要在会话上设置跟踪以查看正在运行的递归 SQL。
【解决方案2】:

根据Oracle's Documentation...

"带引号的标识符开始和结束 带双引号 (")。如果 您使用 带引号的标识符,那么您必须使用 双引号无论何时 你指的是那个对象。”

所以这个...

DROP USER "username" CASCADE;

【讨论】:

    【解决方案3】:

    我知道这是一篇旧帖子,但对于因搜索此问题而偶然发现此问题的任何人 - 问题似乎是数据库触发器正在触发删除用户。 我已经发布了我为 Oracle XE 找到的解决方案(可能与其他 10g 版本相同) here

    希望有人觉得这很有用,

    迈克

    【讨论】:

      【解决方案4】:

      试试DROP USER "'username'"DROP USER ''username''。 (注意最后的那些引号都是单引号)

      【讨论】:

      • 第一个想法是正确的(双引号),第二个(单引号)不行(我想知道自己并尝试过)
      【解决方案5】:

      我不了解 Oracle,但您可以尝试用双引号将其括起来吗?

      (如果有错误我会删除这个答案)

      【讨论】:

        【解决方案6】:

        以下代码可能对您有所帮助:

        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;
        /
        

        【讨论】:

          【解决方案7】:

          再次以更好的格式:

          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;
          /
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2022-01-20
            • 2022-01-15
            • 2018-05-30
            • 2016-03-05
            • 2022-01-22
            • 1970-01-01
            • 2013-11-22
            • 2019-08-11
            相关资源
            最近更新 更多