Create a bat file named setupDB. bat and write the SQL code in it.
- Sqlplus scott/tiger @ zhpt @ createUser. SQL
- Imp dzjc/hldgajjzd file = "dzjc. dmp" ignore = y fromuser = dzjc
- Imp drv_admin/oracleadmin file = "drv_admin.dmp" ignore = y fromuser = drv_admin
- Imp veh_admin/oracleadmin file = "veh_admin.dmp" ignore = y fromuser = veh_admin
- 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
- -- 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 the original DZJC user
- -- DROP USER DZJC CASCADE
- --/
- -- Create the user DZJC with the password hldgajjzd.
- Create user dzjc identified by "hldgajjzd"
- /
- -- Grant DBA permissions to DZJC users
- GRANT DBA TO DZJC
- /
- -- Use the DZJC user to connect to the database
- Conn dzjc/hldgajjzd @ zhpt
- Commit;
- Insert into "DZJC". "DZJC_YHMC" (userid, pwd, username, glbm) VALUES ('0', 'admin888 ', 'admin888', 'admin ');
- Commit;
- -- Create the DRV_DZJC user and set the password to oracleadmin.
- Create user DRV_DZJC identified by "oracleadmin"
- /
- -- Grant DBA permissions to DRV_DZJC users
- Grant dba to DRV_DZJC
- /
- -- Connect to the database with the DRV_DZJC user
- CONN DRV_DZJC/oracleadmin @ zhpt
- /
- Commit;
- -- Create the user VEH_DZJC with the password oracleadmin.
- Create user VEH_DZJC identified by "oracleadmin"
- /
- -- Grant the DBA permission to the VEH_DZJC user
- Grant dba to VEH_DZJC
- /
- -- Use the VEH_DZJC user to connect to the database
- CONN VEH_DZJC/oracleadmin @ zhpt
- /
- Commit;
- 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.