Oracle uses bat batch processing to call the. SQL file, create or delete users, grant users the DBA permission, and import and export user tables.

Source: Internet
Author: User
Create a bat file named setupDB. bat and write the SQL code in it.
  1. Sqlplus scott/tiger @ zhpt @ createUser. SQL
  2. Imp dzjc/hldgajjzd file = "dzjc. dmp" ignore = y fromuser = dzjc
  3. Imp drv_admin/oracleadmin file = "drv_admin.dmp" ignore = y fromuser = drv_admin
  4. Imp veh_admin/oracleadmin file = "veh_admin.dmp" ignore = y fromuser = veh_admin
  5. Pause
sqlplus scott/tiger@zhpt @createUser.sqlimp dzjc/hldgajjzd file="dzjc.dmp" ignore=y fromuser=dzjcimp drv_admin/oracleadmin file="drv_admin.dmp" ignore=y fromuser=drv_adminimp veh_admin/oracleadmin file="veh_admin.dmp" ignore=y fromuser=veh_adminpause

Note:
1: sqlplus scott/tiger @ zhpt @ createUser. SQL indicates connecting to oracle and calling the createUser. SQL file.
2: After executing the createUser. SQL file, run imp dzjc/hldgajjzd file = "dzjc. dmp" ignore = y fromuser = dzjc.
3: pause can stop statement execution on the black window

The content of createUser. SQL is as follows:

SQL code
  1. -- Change sys and zlkj to the user name and password with sysdba permissions (for example, sys user)
  2. Conn sys/zlkj @ dzjc_2005 as sysdba
  3. -- Delete the original DZJC user
  4. -- DROP USER DZJC CASCADE
  5. --/
  6. -- Create the user DZJC with the password hldgajjzd.
  7. Create user dzjc identified by "hldgajjzd"
  8. /
  9. -- Grant DBA permissions to DZJC users
  10. GRANT DBA TO DZJC
  11. /
  12. -- Use the DZJC user to connect to the database
  13. Conn dzjc/hldgajjzd @ zhpt
  14. Commit;
  15. Insert into "DZJC". "DZJC_YHMC" (userid, pwd, username, glbm) VALUES ('0', 'admin888 ', 'admin888', 'admin ');
  16. Commit;
  17. -- Create the DRV_DZJC user and set the password to oracleadmin.
  18. Create user DRV_DZJC identified by "oracleadmin"
  19. /
  20. -- Grant DBA permissions to DRV_DZJC users
  21. Grant dba to DRV_DZJC
  22. /
  23. -- Connect to the database with the DRV_DZJC user
  24. CONN DRV_DZJC/oracleadmin @ zhpt
  25. /
  26. Commit;
  27. -- Create the user VEH_DZJC with the password oracleadmin.
  28. Create user VEH_DZJC identified by "oracleadmin"
  29. /
  30. -- Grant the DBA permission to the VEH_DZJC user
  31. Grant dba to VEH_DZJC
  32. /
  33. -- Use the VEH_DZJC user to connect to the database
  34. CONN VEH_DZJC/oracleadmin @ zhpt
  35. /
  36. Commit;
  37. Exit
-- Change sys and zlkj to the user name and password with sysdba permissions (for example, sys user) conn sys/zlkj @ dzjc_2005 as sysdba -- delete original dzjc user -- drop user dzjc cascade --/-- create user dzjc, the password is hldgajzdcreate user dzjc identified by "hldgajzd"/-- grant dba to dzjc/permissions TO the dzjc user dba -- use the dzjc user to connect TO the database conn dzjc/hldgajjzd @ zhptcommit; insert into "DZJC ". "DZJC_YHMC" (userid, pwd, username, glbm) VALUES ('0', 'admin888 ', 'admin888', 'admin'); commit; -- create a user DRV_DZJC, password: oracleadminCREATE USER DRV_DZJC identified by "oracleadmin"/-- grant dba permission TO DRV_DZJC user dba grant dba to DRV_DZJC/-- use DRV_DZJC user to connect TO database CONN DRV_DZJC/oracleadmin @ zhpt/commit; -- create user VEH_DZJC, the password is oracleadminCREATE USER VEH_DZJC identified by "oracleadmin"/-- grant dba permissions TO VEH_DZJC user dba grant dba to VEH_DZJC/-- use VEH_DZJC user to connect TO database CONN VEH_DZJC/oracleadmin @ zhpt/commit; exit

This file has been commented out clearly.

Finally, let's talk about the batch processing process.
First, connect to Oracle and call createUser. SQL file, createUser. in the SQL file, three new users are created and granted DBA permissions. Then, the system returns to batch processing and executes the imp statement three times, namely, three tables are imported to the new three users.

Imp dzjc/hldgajjzd file = "dzjc. dmp" ignore = y fromuser = dzjc
The user name and password followed by imp, which indicates which user is used to import the exported data.
File is the path of the backup file.
Ignore refers to the append. The data in the user is appended to the table.
Fromuser indicates the user to which the data is imported.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.