Script to Delete more than 1 user from the database

Hi All,
I have a list of users in a file and i want to write a script to delete all these
users from my database.
I have tried deleting users using:
drop user user1,user2,user3..... but it doesn't seem to work.
Can anyone suggest how do i read the users from the file and delete them one by one

You can use an external table :
SYS@db102 SQL> select username from all_users
  2  where username like 'USER%';
USERNAME
USER1
USER2
USER3
SYS@db102 SQL> !cat users_to_drop.txt
USER1
USER2
USER3
SYS@db102 SQL> create table test.users_to_drop
  2  (
  3     userx   char(30)
  4  )
  5    organization external
  6  ( type oracle_loader
  7    default directory work
  8    access parameters
  9     ( records delimited by newline
10     )
11     location ('users_to_drop.txt')
12  )
SYS@db102 SQL> /
Table created.
SYS@db102 SQL> begin
  2     for U in (select userx from test.users_to_drop) loop
  3             dbms_output.put_line('Dropping '||U.userx);
  4             execute immediate 'drop user '||U.userx||' cascade';
  5     end loop;
  6  end;
SYS@db102 SQL> /
Dropping USER1
Dropping USER2
Dropping USER3
PL/SQL procedure successfully completed.
SYS@db102 SQL> select username from all_users
  2  where username like 'USER%';
no rows selected
SYS@db102 SQL>

Similar Messages

  • Delete more than 1 user from the database

    Hi All,
    I have a list of users in a file and i want to write a script to delete all these
    users from my database.
    I have tried deleting users using:
    drop user user1,user2,user3..... but it doesn't seem to work.
    Can anyone suggest how do i read the users from the file and delete them one by one

    I have written a script but getting a error.Can anyone help :-
    create or replace PROCEDURE drop_user
    is
    v_filehandle utl_file.file_type;
    v_user VARCHAR2(20);
    lv1 VARCHAR2(200);
    err_code VARCHAR2(20);
    err_msg VARCHAR2(250);
    BEGIN
    v_filehandle:=utl_file.fopen('/tmp','user_list.lst','R');
    LOOP
    BEGIN
    utl_file.get_line(v_filehandle,v_user);
    lv1:='drop user'|| v_user;
    execute immediate lv1;
    EXCEPTION
    WHEN OTHERS THEN
    err_code := SQLCODE;
         err_msg := substr(SQLERRM, 1, 200);
         dbms_output.put_line(err_code|| ':-' || err_msg);
    END;
    END LOOP;
    utl_file.fclose(v_filehandle);
    END DROP_USER;
    ERROR :
    ERROR at line 1:
    ORA-06510: PL/SQL: unhandled user-defined exception
    ORA-06512: at "SYS.UTL_FILE", line 98
    ORA-06512: at "SYS.UTL_FILE", line 157
    ORA-06512: at "TOM.DROP_USER", line 9
    ORA-06512: at line 1

  • How to delete a purchase order from the database

    I thought that I was in development machine but I was wrong., I have created a purchase order that I would like to delete from the database.
    Thanks in advance.

    >
    Amarnath Reddy Gurappa wrote:
    > Hi ,
    >
    > I would suggest you to put the deletion mark and save the PO .
    >
    > IF you really want to delete the po in the database  then go to the table ekko and
    > ekpo and delete them ,but for this you should have access to se16n and
    > &sap_edit
    PLEASE, do not recommend such, because it is a wrong approach.
    a purchase order has certainly more entries than jsut in table EKKO, and EKPO.  you can check in DB15 how many tables belong to the object MM_EKKO. If you delete jsut entries from EKKO and EKPO, then you create inconsistencies.
    SE16N and &sap_edit, is not anymore possible having current patches installed. SAP revoked this option, because people like you spread this thru the internet and this is causing security issues.
    A phyiscal deletion should only be done via archiving, this is the standard process.
    If you entered something in error, then set the deletion indicator, everybody can do mistakes, but deleting it with irregular options from the database is certainly a much bigger error.

  • HOW TO IMPORT DATA MORE THAN ONCE FROM THE SAME EXPORT DUMP FILE?

    before asking my question i'd like to mention that i'm a french spoke...
    so my english is a little bit bad. sorry for that.
    my problem is : IMPORT
    how to import data a SECOND TIME from an export dump file within oracle?
    My Export dump file was made successfully (Full Export) and then i
    tried to import datas for the first time.
    I got this following message in my logfile: I ADDED SOME COMMENTS
    Warning: the objects were exported by L1, not by you
    . importing SYSTEM's objects into SYSTEM
    REM ************** CREATING TABLESPACES *****
    REM *********************************************
    IMP-00015: following statement failed because the object already exists:
    "CREATE TABLESPACE "USER_DATA" DATAFILE 'E:\ORANT\DATABASE\USR1ORCL.ORA' SI"
    "ZE 3145728 DEFAULT STORAGE (INITIAL 10240 NEXT 10240 MINEXTENTS 1 MAX"
    "EXTENTS 121 PCTINCREASE 50) ONLINE PERMANENT"
    IMP-00015: following statement failed because the object already exists:
    "CREATE TABLESPACE "ROLLBACK_DATA" DATAFILE 'E:\ORANT\DATABASE\RBS1ORCL.ORA"
    "' SIZE 10485760 DEFAULT STORAGE (INITIAL 10240 NEXT 10240 MINEXTENTS "
    "1 MAXEXTENTS 121 PCTINCREASE 50) ONLINE PERMANENT"
    etc........
    IMP-00017: following statement failed with ORACLE error 1119:
    "CREATE TABLESPACE "L1" DATAFILE 'E:\ORADATA\L1.DBF' SIZE 1048576000 "
    "DEFAULT STORAGE (INITIAL 10240 NEXT 10240 MINEXTENTS 1 MAXEXTENTS 121 PCTIN"
    "CREASE 50) ONLINE PERMANENT"
    IMP-00003: ORACLE error 1119 encountered
    ORA-01119: error in creating database file 'E:\ORADATA\L1.DBF'
    ORA-09200: sfccf: error creating file
    OSD-04002: unable to open file
    O/S-Error: (OS 3) The system cannot find the path specified
    --->etc..........
    the drive E: with the folder E:\ORADATA didn't exist, but after
    all that i created it.
    see below, before my IMPORT statement
    REM ********************* CREATING USER *********
    REM ********************************************
    IMP-00017: following statement failed with ORACLE error 959:
    "CREATE USER "L1" IDENTIFIED BY VALUES 'A6E0DAA6865E7627' DEFAULT TABLESPACE"
    " "L1" TEMPORARY TABLESPACE "TEMPORARY_DATA""
    IMP-00003: ORACLE error 959 encountered
    ORA-00959: tablespace 'L1' does not exist
    IMP-00017: following statement failed with ORACLE error 959:
    "CREATE USER "MLCO" IDENTIFIED BY VALUES '56AC6447B7D50467' DEFAULT TABLESPA"
    "CE "MLCO" TEMPORARY TABLESPACE "TEMPORARY_DATA""
    IMP-00003: ORACLE error 959 encountered
    ORA-00959: tablespace 'MLCO' does not exist
    ETC.......
    REM ********************* GRANTING ROLES ***********
    REM ************************************************
    IMP-00017: following statement failed with ORACLE error 1917:
    "GRANT ALTER ANY TABLE to "L1" "
    IMP-00003: ORACLE error 1917 encountered
    ORA-01917: user or role 'L1' does not exist
    ETC.........
    IMP-00017: following statement failed with ORACLE error 1918:
    "ALTER USER "L1" DEFAULT ROLE ALL"
    IMP-00003: ORACLE error 1918 encountered
    ORA-01918: user 'L1' does not exist
    -- that is normal, since the creation of the
    tablespace failed !!
    REM******************************
    IMP-00015: following statement failed because the object already exists:
    "CREATE ROLLBACK SEGMENT RB_TEMP STORAGE (INITIAL 10240 NEXT 10240 MINEXTENT"
    "S 2 MAXEXTENTS 121) TABLESPACE "SYSTEM""
    IMP-00015: following statement failed because
    . importing SCOTT's objects into SCOTT
    IMP-00015: following statement failed because the object already exists:
    "CREATE SEQUENCE "EVT_PROFILE_SEQ" MINVALUE 1 MAXVALUE 999999999999999999999"
    "999999 INCREMENT BY 1 START WITH 21 CACHE 20 NOORDER NOCYCLE"
    ETC............
    importing L1's objects into L1
    IMP-00017: following statement failed with ORACLE error 1435:
    "ALTER SCHEMA = "L1""
    IMP-00003: ORACLE error 1435 encountered
    ORA-01435: user does not exist
    REM *************** IMPORTING TABLES *******************
    REM ****************************************************
    . importing SYSTEM's objects into SYSTEM
    . . importing table "AN1999_BDAT" 243 rows imported
    . . importing table "BOPD" 112 rows imported
    . . importing table "BOINFO_AP" 49
    ETC................
    . . importing table "BO_WHF" 2 rows imported
    IMP-00015: following statement failed because the object already exists:
    "CREATE TABLE "DEF$_CALL" ("DEFERRED_TRAN_DB" VARCHAR2(128),
    IMP-00015: following statement failed because the object already exists:
    "CREATE SYNONYM "DBA_ROLES" FOR "SYS"."DBA_ROLES""
    IMP-00015: following statement failed because the object already exists:
    "CREATE SYNONYM "DBA_ERRORS" FOR "SYS"."DBA_ERRORS""
    IMP-00008: unrecognized statement in the export file:
    . importing L1's objects into L1
    IMP-00017: following statement failed with ORACLE error 1435:
    "ALTER SCHEMA = "L1""
    IMP-00008: unrecognized statement in the export file:
    J
    Import terminated successfully with warnings.
    -------------------------------------b]
    So after analysing this log file, i created
    the appropriate drives and folders... as the
    import statement doesn't see them.
    E:\ORADATA G:\ORDATA etc...
    And i started to [b]IMPORT ONE MORE TIME. with:
    $ IMP73 sys/pssw Full=Y FILE=c:\temp\FOLD_1\data_1.dmp BUFFER=64000
    COMMIT=Y INDEXFILE=c:\temp\FOLD_1\BOO_idx.sql
    LOG=c:\temp\FOLD_1\BOO_log.LOG DESTROY=Y IGNORE=Y;
    after that i could not see the users nor the
    tables created.
    and the following message appeared in the log file:
    Warning: the objects were exported by L1, not by you
    . . skipping table "AN1999_BDAT"
    . . skipping table "ANPK"
    . . skipping table "BOAP"
    . . skipping table "BOO_D"
    ETC.....skipping all the tables
    . . skipping table "THIN_PER0"
    . . skipping table "UPDATE_TEMP"
    Import terminated successfully without warnings.
    and only 2 new tablespaces (originally 3) were
    created without any data in ( i check that in
    the Oracle Storage manager : the tablespaces exit
    with 0.002 used space; originally 60 M for each !!)
    so,
    How to import data (with full import option) succefully
    MORE THAN ONE TIME from an exported dump file ?
    Even if we have to overwrite tablespaces , tables and users.
    thank you very much

    The Member Feedback forum is for suggestions and feedback for OTN Developer Services. This forum is not monitored by Oracle support or product teams and so Oracle product and technology related questions will not be answered. We recommend that you post this thread to the appropriate Database forum.
    The main URL is:
    http://forums.oracle.com/forums/index.jsp?cat=18

  • My iPhone will not download more than 50mb from the app store.

    I have fast iPhone LTE unlimited service from my provider. If my download is larger than 50MB I have to switch to wifi. At work my wifi connection is 2.5MB and my LTE service is 20MB. How do I stay at the fast speed for the download?  Was this an oversite on apple's side?
    Waiting for help.

    it's supposed to be that way so you don't kill your data plan.

  • How to handle the more than once from the same jsp files

    Hi,
    i have a one jsp file with three buttons.each one having for different functionalities. like one for cancel, second for edit the values and third for save the values in databse. so i want to handle all these 3 buttons. how can test that which button is coming for action..
    Is there any validation necessary for buttons....
    give me the suggestion to do this.......
    help meeeeeeee
    thanks
    123

    Hint: Its something you need to handle using javascript by setting the hidden variables during submit.
    I would expect you to think on this and reply the simple solution.

  • How do I delete more than 1 slide at a time from the custom slide show in Elements 8

    How do I Delete more than 1 slide at a time from the custom slide show in Elements 8?

    How to Mass Delete Emails from iPhone and iPad Inbox (with video)
    http://suiteminute.com/how-to-mass-delete-emails-from-iphone-and-ipad-inbox/
     Cheers, Tom

  • How to delete more than one workbook from command line

    Hi, I'd like to delete more than one workbook from command line:
    The following syntax, it doesn't work....but I followed the manual instructions:
    dis51adm.exe /connect eul/eul@uatdb /delete /workbook "ALE_TEST_1, ALE_TEST_2" /eul eul /log D:\Ale\delete.log
    where:
    eul/eul@uatdb: is the db’s schema/user where the EUL is installed;
    /delete "ALE_TEST_1, ALE_TEST_2": is the command to delete the workbooks, specified inside the “” (with the relative path)
    /log D:\Ale\delete.log: is the command to write a log’s file named “delete.log” to track the action     
    The log file says:
    22/4/2008 4:00:26 μμ
    dis51adm.exe /connect /delete /workbook ALE_TEST_1, ALE_TEST_2 /eul eul /log D:\Ale\delete.log
    Document ALE_TEST_1, ALE_TEST_2 not found in EUL.
    Internal EUL Error: ObjectNotFound - Can't find EUL element
    There are 0 eul elements to be deleted.
    Completed deleting eul elements.
    22/4/2008 4:00:29 μμ
    Anyone can tell me how is the right syntax ?
    Thanks in advance
    Alex

    Hi Rod
    I was coming to that conclusion myself but wanted to wait until the other avenues had been exhausted first - aka making sure of the workbook names.
    I checked through all of the command line documentation and read nothing which clearly indicated that only one workbook could be processed at a time, other than the fact that the syntax says workbook and not workbooks, which could be a big clue.
    I think you are right though in that it has to be one at a time, which would be a pain.
    Best wishes
    Michael

  • Deleting more than one file at a time from Nomad Jukebox Zen Xtra 4

    Is there a way to delete more than one file at a time from Zen Xtra? Actually, I'd like to delete most of the 800+ files and the only way I've found is to do them one at a time..! Help!

    Either use finder to drag and drop those tracks onto
    "Library" in iTunes' left "Source" column or from
    iTunes Menu Files use "Add to Library ..." then
    navigate to a folder that keep a yoru tracks and
    select that folder.
    This did it! I was doing an "import" which would only let me do one song at a time. But the "add to library" and the drag and drop both worked. Thanks!!!
    New Mac user
    Scott in Alaska
    MacBookPro   Mac OS X (10.4.5)  

  • Cannot delete more than 4 e-mails from trash folder in one go

    When I try to delete more than 4 e-mails in one go from the trash folder on my Sony Xperia Z2, the e-mail software crashes with the message: 'Unfortunately, E-mail has stopped'. Is this a bug everyone is experiencing on the Z2?

    Thank you Thommo, your instructions have solved the problem. I cleared cache and data which got rid of the 4000+ e-mails in my bin folder. Then rebooted and inputted my e-mail account details. The e-mail app downloaded 157 e-mails from the TalkTalk server. I deleted them, and then deleted the same 157 e-mails from the bin folder... and it worked.
    Thanks for your help.

  • Is there a way to delete more than one photo at a time in the Photo application?

    Is there a way to delete more than one photo at a time in the application Photos in the iPad? Thanks.

    The links below have instructions for deleting photos.
    iOS and iPod: Syncing photos using iTunes
    http://support.apple.com/kb/HT4236
    iPad Tip: How to Delete Photos from Your iPad in the Photos App
    http://ipadacademy.com/2011/08/ipad-tip-how-to-delete-photos-from-your-ipad-in-t he-photos-app
    Another Way to Quickly Delete Photos from Your iPad (Mac Only)
    http://ipadacademy.com/2011/09/another-way-to-quickly-delete-photos-from-your-ip ad-mac-only
    How to Delete Photos from iPad
    http://www.wondershare.com/apple-idevice/how-to-delete-photos-from-ipad.html
    How to: Batch Delete Photos on the iPad
    http://www.lifeisaprayer.com/blog/2010/how-batch-delete-photos-ipad
    (With iOS 5.1, use 2 fingers)
    How to Delete Photos from iCloud’s Photo Stream
    http://www.cultofmac.com/124235/how-to-delete-photos-from-iclouds-photo-stream/
     Cheers, Tom

  • TS3899 How do I delete more than one email at a time from my i phone 5C

    How do I delete more than one email at a time from my i phone 5C

    With your Mail app open and the listing of the messages, tap Edit at the top right.  Then check each circle on the left side of the messages to delete.  When you have checked those to delete, tap Trash at the lower right.
    Next tap Mailboxes upper left, under accounts select the account, then for the account tap Trash.  Select Edit upper right, and at the bottom, Delete All, and confirm Delete All and all will be removed at one time.

  • I want to delete more than one song at a time from iTunes

    I want to delete whole albums from itunes. Is there a way to delete more than one song at a time?

    Or Command click on the songs if they are not consecutive on the list.

  • The info supplied does not show how to delete more than one bookmark, only folders

    I read the info provided online for deleting more than one bookmark/folder but it doesn't show how for multiple bookmarks. My OS is XP. with updated Firefox version.
    When I go to Bookmarks>Show All Bookmarks, there is no listing of the ind bookmarks, only the folders.
    Whoever used this pc before had lots and lots and I do not want to have to delete them all one-by-one.
    Please advise---

    ''Library List only shows Folders, how do I delete bookmarks''
    Usually one deletes a lot of history items so the techniques were described in the history areas by including some pictures. The techniques work the same for bookmarks.
    You can select '''multiple entries without invoking the bookmark''' for dragging, copying, moving or deleting, (similar to how you can [http://kb.mozillazine.org/Viewing_the_browsing_history_-_Firefox#Selecting_history_items select multiple browsing history items]) with use of the Ctrl''/Cmd'' key (to add to a selection) & Shift key (to extend a selection) by clicking to the '''left''' of the favicon (webpage icon) in the list to make selection(s). To extend from the last selection made of dis-contiguous entries use Ctrl''/Cmd''+Shift+click. Makes moving several bookmarks from different places to a new location easier as well, and of course for your interest in deleting bookmarks.
    Whether you are selecting from the Side Panel or from the Library List, you generally want to start with a search specifying one or more strings within Titles, url/location, or tags. The search with strings of characters works the same in the Location Bar (before Enter known as the AwesomeBar feature), and in bookmark, history and tab searches.
    Within the Library List you will only see bookmarks by selecting a folder, or by doing a search.
    Articles: (read entire articles but am pointing to specific areas)
    *http://kb.mozillazine.org/Viewing_the_browsing_history_-_Firefox#Selecting_history_items
    *http://kb.mozillazine.org/Sorting_and_rearranging_bookmarks_-_Firefox#Bookmarks_Manager_or_Library_window
    *http://kb.mozillazine.org/Location_Bar_search#Location_Bar_search_.28internal_-_Auto_Complete.29
    <br><small>Please mark "Solved" one answer that will best help others with a similar problem -- hope this was it.<small>

  • Using Powershell to delete all users from the Portal

    Summary
    This script will delete all users from the Portal except for Administrator and the Built-In Sync account.
    Based on Markus's "Delete a User" script.
    Useful when developing your system if you want to quickly clear out the data and start again.
    set-variable -name URI -value "http://localhost:5725/resourcemanagementservice' " -option constant
    function DeleteObject
    PARAM($objectType, $objectId)
    END
    $importObject = New-Object Microsoft.ResourceManagement.Automation.ObjectModel.ImportObject
    $importObject.ObjectType = $objectType
    $importObject.TargetObjectIdentifier = $objectId
    $importObject.SourceObjectIdentifier = $objectId
    $importObject.State = 2
    $importObject | Import-FIMConfig -uri $URI
    if(@(get-pssnapin | where-object {$_.Name -eq "FIMAutomation"} ).count -eq 0) {add-pssnapin FIMAutomation}
    $allobjects = export-fimconfig -uri $URI `
    –onlyBaseResources `
    -customconfig "/Person"
    $allobjects | Foreach-Object {
    $displayName = $_.ResourceManagementObject.ResourceManagementAttributes | `
    Where-Object {$_.AttributeName -eq "DisplayName"}
    if([string]::Compare($displayName.Value, "Administrator", $True) -eq 0)
    {write-host "Administrator NOT deleted"}
    elseif([string]::Compare($displayName.Value, "Built-in Synchronization Account", $True) -eq 0)
    {write-host "Built-in Synchronization Account NOT deleted"}
    else {
    $objectId = (($_.ResourceManagementObject.ObjectIdentifier).split(":"))[2]
    DeleteObject -objectType "Person" `
    -objectId $objectId
    write-host "`nObject deleted`n" $displayName.Value }
    Go to the FIM ScriptBox
    http://www.wapshere.com/missmiis

    The DeleteObject function opens and closes a connection for each object.  This approach is faster:
    http://social.technet.microsoft.com/wiki/contents/articles/23570.how-to-use-powershell-to-delete-fim-users-that-have-a-null-attribute-name.aspx
    Mike Crowley | MVP
    My Blog --
    Planet Technologies

Maybe you are looking for