How to use script files to manage Oracle databases

Source: Internet
Author: User
For example, you can reduce the command input. For example, you can save the commands that pass the debugging test so that you can use them again when needed. For example, you can avoid input errors. Although the SQL * Plus program editing tool provided by the Oracle database provides a certain degree of reality, editing, and modifying SQL Buffer commands, its ability to edit commands is

For example, you can reduce the command input. For example, you can save the commands that pass the debugging test so that you can use them again when needed. For example, you can avoid input errors. Although the SQL * Plus program editing tool provided by the Oracle database provides a certain degree of reality, editing, and modifying SQL Buffer commands, its ability to edit commands is

For example, you can reduce the command input. For example, you can save the commands that pass the debugging test so that you can use them again when needed. For example, you can avoid input errors. Although the SQL * Plus program editing tool provided by the Oracle database provides a certain degree of reality, editing, and modifying SQL Buffer commands, its ability to edit commands is very weak, and operations are not as convenient as script files. Therefore, many database management experts like to make some common commands into script files. You can directly call the script file when you need it later. For example, I have saved nearly useful script files. When needed, you only need to take the script file, and some can be directly executed; some can be used as long as they are slightly modified according to the actual situation.

Therefore, I think that script files are an indispensable tool in Oracle Database Management. In fact, using script files to manage Oracle databases is not as difficult as you may think. Through this article, you may be able to eliminate this fear.

Step 1: Create a script file.

There are many ways to create script files when the Oracle database is heavy. For example, you can directly create a script file in notepad or using SQL * Plus. However, the author's opinion is that it is troublesome to directly create a script file in SQL * Plus. This is mainly because the command editing capability is very effective in the SQL * Plus tool. For example, you cannot use the arrow keys on the keyboard to locate the input position, or use the DEL key to delete the input content. It is also difficult to read.

My favorite practice is to write the script statements in some editors, such as text files, and then copy them directly to the SQL * Plus tool for testing. If the test passes, you can save it for use next time. Therefore, using a third-party script statement editing tool, there is a defect that the statement cannot be directly tested. Manually copy and paste it to the Oracle environment for testing. However, this is worthwhile for command editing. After all, editing a script statement in a third-party tool is much easier than editing a script in SQL * Plus. I don't know why I didn't develop a decent script statement editor for database management software such as Oracle.

Note that, in SQL * Plus statements, you can save untested or wrong script statements. However, doing so will only waste time. In order to improve the availability of script statements, I strongly recommend that the database administrator not be too confident. After writing the script statements, you must test them. The script can be archived only when the script statement has been verified as useful.

Secondly, if you use notepad or other tools to write script statements, you are advised to change the extension of the script file to SQL in order to directly call this script file in the Oracle environment. This is the script file extension recognized by the Oracle database.

For the database administrator who first contacts the script file, pay attention to the script file format. In general, it is similar to a common SQL statement. It should only be noted in two aspects. First, add the "/" symbol to the last line of the script file. This symbol indicates that the database can now execute this statement. Second, do not add the ";" sign in the last SQL statement. Otherwise, the next time you run the script statement, an error will occur.

Finally, when writing a script file, pay attention to the variable issue in the script file. If the script file requires external input parameters, the SQL * Plus tool will use these external input values to replace the replacement parameters in the script file during execution, in the script file, the replacement parameter life method is slightly different from the variable declaration method in the Oracle database for functions and procedures. In the script file, you do not need to declare the parameters before they are replaced. Instead, you can directly use & 1 & 2 to describe it.

Step 2: edit the script file.

When we use a script file, we often need to adjust it slightly according to the actual situation. You can edit a script file in either of the following ways. The first is through the SQL * Plus tool, and the second is the third-party independent script editing software.

For some script files with minor adjustments, we can directly use SQL * Plus to open and edit them. However, for script files that require a large number of modifications, the author suggests that the database administrator use a third-party independent script editing software. The reason is very simple. As mentioned above, the script command editing function of SQL * Plus is very weak. If you use this tool to edit the existing script statements, the workload may be reduced by writing a new one. Therefore, the database administrator should select an appropriate script editing tool based on the actual situation.

In addition, pay attention to the correctness of the syntax During the editing process. In particular, you cannot change the format. For example, do not accidentally delete the end of the last "/" symbol, and so on. I like to use Microsoft notepad as a script editing tool. He is convenient and does not need to go online to find professional script editing tools. That is to say, it is easy to worry, and it is able to meet the regular needs of our database administrators!

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.