Executing a Script
Most of this chapter has focused on what you need to know in order to enter a command directly into SQL*Plus and have it executed. Another option available to you is to have SQL*Plus execute a script. A script is simply a text file that contains one or more statements to execute. When SQL*Plus executes a script, the commands or statements in the file are executed just as if you had typed them in directly from the keyboard. A script file can contain any combination of valid SQL*Plus commands, SQL statements, or PL/SQL blocks.
The START command is used to execute a script. Here is the syntax to use:
STARTfilename[arg1arg2arg3...]
where:
- STA[RT]
May be abbreviated to STA.
- filename
Is the name of the script file you want to execute. The default extension is
.SQL.- arg1 arg2 arg3
Represent any command-line arguments you want to pass to the script file. These are delimited by spaces, and you may specify as many as are needed by the script. Arguments containing spaces should be enclosed in either single or double quotes.
Let’s say you had a file named
DESCRIBE_ALL.SQL, and it contained the following
SQL*Plus commands:
DESCRIBE employee DESCRIBE project DESCRIBE project_hours
You could execute this file with the START command as shown here:
SQL> START C:\JONATHAN\SQL_PLUS_BOOK\XB_CH_2\DESCRIBE_ALL Name Null? Type ------------------------------- -------- ---- EMPLOYEE_ID NOT NULL NUMBER EMPLOYEE_NAME VARCHAR2(40) EMPLOYEE_HIRE_DATE DATE EMPLOYEE_TERMINATION_DATE DATE EMPLOYEE_BILLING_RATE ...