Executing a Script

Most of this chapter has focused on what you need to know 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, which 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.

Let's say you have a file named ex2-17.sql, and it contains the following SQL*Plus commands:

SET ECHO ON


DESCRIBE employee
DESCRIBE project
DESCRIBE project_hours

You can execute this file using the @ command, as shown in Example 2-17. Type an @ character, follow it by the path to the script you wish to execute, and press Enter.

Example 2-17. Executing a SQL*Plus script

SQL> @$HOME/sqlplus/ExampleScripts/ex2-17 SQL> DESCRIBE employee Name Null? Type ----------------------------------------- -------- ---------------- EMPLOYEE_ID NOT NULL NUMBER EMPLOYEE_NAME VARCHAR2(40) EMPLOYEE_HIRE_DATE DATE EMPLOYEE_TERMINATION_DATE DATE EMPLOYEE_BILLING_RATE NUMBER(5,2) SQL> DESCRIBE project Name Null? Type ----------------------------------------- -------- ---------------- PROJECT_ID NOT NULL NUMBER(4) PROJECT_NAME VARCHAR2(40) PROJECT_BUDGET NUMBER(9,2) SQL> DESCRIBE project_hours Name Null? Type ----------------------------------------- -------- ---------------- ...

Get Oracle SQL*Plus: The Definitive Guide, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.