Scenario:
The DBA exported all the creation scripts for storage, functions, and other objects to me, with thousands of files.
Now, how do I import these object creation scripts to another database?
Manual execution is obviously not realistic.
Therefore, a batch is manually written to form a. SQL script for all the files. Finally, the. SQL script generated by @ is imported to the target database.
OS: WINDOWS xp
The script content is as follows:
@ Echo offif exist list. SQL del list. SQL/q: inputclsset input =: set/p input = enter the path to be judged: set "input = % input:" = % ":: the above sentence is used to determine whether quotation marks exist in % input %. If yes, the quotation marks are removed. If "% input %" = ": "goto inputif not exist" % input % "goto inputfor/f" delims = "% I in ('dir/B/a-d/s" % input % "') do echo % ~ Fnxi> list. sqlif not exist list. SQL goto no_filestart list. sqlexit: no_fileclsecho % cur_dir % error. The list. SQL script is not generated successfully! Pause
Usage:
After saving the file as a. BAT type, double-click it to execute.
Enter the path of your script:
For example, there are the following types of files in my e-drive CRY Folder:
TEST. PRC
...
123TEST1. FNC (with subfolders 123)
...
TEST2.VW
..
After the batch processing is executed, the final list. SQL script file is as follows (the file is automatically opened in the default editor after the batch processing is executed ):
@ E: cryTEST. PRC
...
@ E: cry123TEST1. FNC
...
@ E: cryTEST2.VW
...
Open SQLPLUS to specify the user to log on to the database, and then execute: (my script file is generated on disk D)
@ D: list. SQL
In this way, all objects are automatically generated under the specified user.
---------------------------
Note: many objects generated in this way are invalid because they are not generated in order. Therefore, we recommend that you compile all invalid objects after automatic execution.