SQL* Plus CLI  «Prev  Next»

Lesson 8SQL*Plus @ command
Objective Execute scripts written for SQL*Plus.

SQL*Plus @ Command(execute Oracle scripts)

To have SQL*Plus read commands from a file and execute them, use the @ command. The syntax for the @ command looks like this:


The default extension is ".sql". The path defaults to your current working directory. The following example shows the @ command being used to execute the db_objects_by_type.sql file created in the previous
SQL> @c:\db_objects_by_type

------------ ---------- ---------------------------

Running Scripts

The START command retrieves a script and runs the commands it contains. Use START to run a script containing SQL commands, PL/SQL blocks, and SQL*Plus commands. You can have many commands in the file. Follow the START command with the name of the file:
START file_name

SQL*Plus assumes the file has a .SQL extension by default.

Example 5–8 Running a Script

To retrieve and run the command stored in SALES.SQL, enter

SQL*Plus runs the commands in the file SALES and displays the results of the commands on your screen, formatting the query results according to the SQL*Plus commands in the file:
Output of the SALES script.

You can also use the @ (at sign) command to run a script:
The @ and @@ commands list and run the commands in the specified script in the same manner as START. SET ECHO affects the @ and @@ commands in the same way as it affects the START command. To see the commands as SQL*Plus "enters" them, you can SET ECHO ON. The ECHO system variable controls the listing of the commands in scripts run with the START, @ and @@ commands. Setting the ECHO variable OFF suppresses the listing. START, @ and @@ leave the last SQL command or PL/SQL block of the script in the buffer.

If you do not want to specify the path for each script that you run, you can give SQL*Plus a list of directories to search each time you run a script.
Windows users especially, may want to do this because under Windows NT the default directory will be the Oracle bin directory.
SQL*Plus allows you to nest scripts--you can have one script use the @ command to call another. When you do that, you may want to use @@ instead.