How to run a script file in sql*plus


















Examine the error message; it indicates an invalid column name in line 1 of the query. Instead of re-entering the entire command, you can correct the mistake by editing the command in the buffer. The line containing the error is now the current line.

This command has three parts, separated by slashes or any other non-alphanumeric character:. The CHANGE command finds the first occurrence in the current line of the character sequence to be changed and changes it to the new sequence. Re-enter the line by typing the line number followed by a space and the new text and pressing Return. Now that you have corrected the error, you can use the RUN command to run the command again:.

To insert a line before line 1, enter a zero "0" and follow the zero with text. Press Return again to indicate that you will not enter any more lines, and then use RUN to verify and re-run the query. To append a space and the clause DESC to line 4 of the current query, first list line Type RUN to verify the query:.

Suppose you want to delete the current line to the last line inclusive. Use the DEL command as shown below. For further information about using comments in scripts, see "Notes on Placing Comments". Since there is no ending delimiter, the comment cannot span multiple lines. For example, these comments are legal:. Move the comment to avoid this error. For example:. You can have many commands in the file. To run a series of scripts in sequence, first create a script containing several START commands, each followed by the name of a script in the sequence.

The command may be useful in this example. See the EXIT command in this chapter for further information. If your script generates a SQL error while running from a batch file on the host operating system, you may want to abort the script and exit with a return code.

Note that you can also define user variables to use in titles and to save your keystrokes by defining a long string as the value for a variable with a short name. You can enter any string at the prompt, even one containing blanks and punctuation. If the SQL command containing the reference should have quote marks around the variable and you do not include them there, the user must include the quotes when prompted.

You should avoid creating substitution variables with names that may be identical to values that you will pass to them, as unexpected results can occur. If a value supplied for a substitution variable matches a variable name, then the contents of the matching variable are used instead of the supplied value.

Add a comment. Active Oldest Votes. If your filename is myQueries. Thanks a lot bhattdon. This was exactly what I was looking for. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Are you executing this with "sqlplus I find different behaviours depending which one you do on Unix. Add a comment. Active Oldest Votes. Improve this answer. Dave Costa Dave Costa 1, 1 1 gold badge 10 10 silver badges 3 3 bronze badges.

The sqlplus command runs the script then tries to read more commands from standard input. With this pipeline, the read from standard input will read the string "exit" from the echo command, causing sqlplus to exit. Beware that you expose your username password through the proces list on unix ps -ef but i'm almost sure it works the same way on windows — Rob van Laarhoven. Show 2 more comments. While this may technically answer the Question, it's substantially a duplicate of other Answers and adds little value.

Also, It would help others if you explained what these commands are doing. Thank you! This worked for me and I find it more elegant than the top answer because it avoids 'exit'. It tells sqlplus to execute the statemet s above it. Chris Noe Chris Noe 1 1 silver badge 6 6 bronze badges. Note that Dave Costa's answer works too: piping exit or quit into the sqlplus command.

The slash means to execute what is in the SQL buffer. About Using Bind Variables. Read this chapter while sitting at your computer and try out the examples shown.

This is especially useful for storing complex commands or frequently used reports. Your operating system may have one or more text editors that you can use to write scripts. For example, to define the editor used by EDIT to be vi, enter the following command:. To create a script with a text editor, enter EDIT followed by the name of the file to edit or create, for example:. EDIT adds the filename extension.

SQL to the name unless you specify the file extension. When you save the script with the text editor, it is saved back into the same file. EDIT lets you create or modify scripts.

Suppose you have composed a query to display a list of salespeople and their commissions. You plan to run it once a month to keep track of how well each employee is doing. To compose and save the query using your system editor, invoke your editor and create a file to hold your script:. Enter each of the following lines in your editor.

Do not forget to include the semicolon at the end of the SQL statement:. This line is called the current line. It is marked with an asterisk when you list the current command or block. Suppose you want to list the current command.

Use the LIST command as shown. Various actions determine which line is the current line:. If you get an error , the error line automatically becomes the current line. Examine the error message; it indicates an invalid column name in line 1 of the query. Instead of re-entering the entire command, you can correct the mistake by editing the command in the buffer. The line containing the error is now the current line.

This command has three parts, separated by slashes or any other non-alphanumeric character:. The CHANGE command finds the first occurrence in the current line of the character sequence to be changed and changes it to the new sequence. To insert a line before line 1, enter a zero "0" and follow the zero with text. Press Return again to indicate that you will not enter any more lines, and then use RUN to verify and re-run the query.

Suppose you want to add a fourth line to the SQL command you modified in Example



0コメント

  • 1000 / 1000