SQL*Plus allows you to save the contents of the buffer to a file and to read that file back again. If you have built up a long and complicated SQL statement, you can save it for reuse later, and save yourself the bother of figuring it all out again. Two commands, GET and SAVE, are provided for this purpose.
The SAVE command allows you to save the current contents of the buffer to a file. Here is the syntax for SAVE:
May be abbreviated SAV.
Is the name of the file to which you want to save the buffer. The
default extension is
.SQL, but you may specify
another if you like.
Tells SQL*Plus that you want to create a new file. The save will fail if the file you’ve specified already exists. This is the default behavior.
Tells SQL*Plus to save the buffer to the file specified, regardless of whether or not that file already exists. If the file does exist, it will be overwritten.
Tells SQL*Plus to add the contents of the buffer to an existing file.
The following example shows the SAVE command being used to save the contents of a rather long SQL query to a file. First the query is entered into the buffer without being executed; then the SAVE command is used to write the buffer to a file.
SELECT employee_name, project_name2
FROM employee, project, project_hours3
WHERE employee.employee_id = project_hours.employee_id4
AND project_hours.project_id = project.project_id5 ...