O'Reilly logo

Oracle SQL*Plus: The Definitive Guide by Jonathan Gennick

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Saving and Retrieving the Buffer

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.

SAVE

The SAVE command allows you to save the current contents of the buffer to a file. Here is the syntax for SAVE:

SAVE filename [CREATE|REPLACE|APPEND]

where:

SAV[E]

May be abbreviated SAV.

filename

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.

CRE[ATE]

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.

REPLACE

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.

APPEND

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.

SQL>   SELECT employee_name,  project_name
  2      FROM employee, project, project_hours
  3     WHERE employee.employee_id = project_hours.employee_id
  4       AND project_hours.project_id = project.project_id 5  ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required