Drop the user if it exists : User Password « User Previliege « Oracle PL / SQL






Drop the user if it exists

   
SQL>
SQL> DEF username = plsql
SQL> DEF default_ts = USERS
SQL> DEF temp_ts = TEMP
SQL>
SQL> SET FEEDBACK OFF SERVEROUTPUT ON VERIFY OFF TERMOUT OFF
SQL>
SQL> SPOOL create_user.log
SQL>
SQL> DECLARE
  2     v_count       INTEGER        := 0;
  3     v_statement   VARCHAR2 (500);
  4  BEGIN
  5
  6    
  7
  8     SELECT COUNT (1) INTO v_count FROM dba_users WHERE username = UPPER ('&username');
  9
 10     IF v_count != 0
 11     THEN
 12        EXECUTE IMMEDIATE ('DROP USER &username CASCADE');
 13     END IF;
 14
 15     v_count := 0;
 16
 17  EXCEPTION
 18     WHEN OTHERS
 19     THEN
 20        DBMS_OUTPUT.put_line (SQLERRM);
 21        DBMS_OUTPUT.put_line ('   ');
 22  END;
 23  /
SQL>
SQL> SET FEEDBACK ON TERMOUT ON
SQL>
SQL> SET FEEDBACK ON
SQL>
SQL> SPOOL OFF
SQL>
SQL>

   
    
    
  








Related examples in the same category

1.create user chris identified by chris;
2.Change User password
3.make a password expire with the ALTER USER command
4.Alter user to change the password
5.Get user name from all_users
6.Unassign Role from User
7.Remove user