| Lesson 5 | SQL*Plus File Location |
| Objective | Describe the file location of a saved file in SQL*Plus. |
When you use commands like SAVE, START, @, or EDIT in SQL*Plus, you are working with files on the operating system. To use these features effectively, you must understand where SQL*Plus saves and loads those files. This lesson explains how SQL*Plus determines the default directory for script files and how you can confirm or change that location.
By default, SQL*Plus saves and loads files in the current working directory of your SQL*Plus session unless you specify a full or relative path in your command.
sqlplus.
BIN or installation directory defined in the shortcut for the Oracle client software. The exact path depends on the operating system and how the Oracle client was installed.
Any scripts you save or run without specifying a path will be stored in, or loaded from, this current directory.
You can always check where SQL*Plus is reading and writing files by using the HOST command to run operating system commands from inside SQL*Plus.
To see the list of files in the current directory, use:
SQL> HOST DIR
This opens a directory listing from the folder where SQL*Plus is currently working. Any scripts you save without a path (for example, SAVE report1) will appear in this directory as .sql files.
To find the current working directory, use:
SQL> HOST PWD
You can also list files with:
SQL> HOST ls
The directory reported by PWD is where SQL*Plus will save and look for files when you do not specify a path.
When you work with files, SQL*Plus combines its file commands with the current directory as follows:
SQL> SAVE monthly_sales
This creates monthly_sales.sql in the current directory unless you specify a different path.
SQL> @monthly_sales
SQL*Plus looks for monthly_sales.sql in the current directory.
SQL> EDIT monthly_sales
SQL*Plus expects monthly_sales.sql in the current directory unless you provide a full or relative path.
If SQL*Plus cannot find the file in the current directory, it will return a “file not found” error. In that case, either change to the correct directory before starting SQL*Plus, or include an explicit path in your command.
You are not limited to the default location. You can specify a full or relative path in your file commands to work with scripts stored elsewhere.
For example:
SQL> SAVE C:\oracle\scripts\monthly_sales REPLACE
SQL> @C:\oracle\scripts\monthly_sales
On Linux/UNIX:
SQL> SAVE /u01/app/oracle/scripts/monthly_sales REPLACE
SQL> @/u01/app/oracle/scripts/monthly_sales
In these examples, SQL*Plus reads and writes directly to the specified directory instead of the default working directory.
To reliably understand and control where your SQL*Plus files are saved:
scripts folder).HOST DIR (Windows) or HOST PWD / HOST ls (Linux/UNIX).SAVE, knowing they will be written to the current directory if no path is specified.START or @, understanding that SQL*Plus searches the current directory when you do not supply a path.By keeping track of the current directory and using explicit paths when needed, you can always describe and control where SQL*Plus saves and retrieves your script files.