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 later reuse and save yourself the bother of figuring it all out again. Two commands, SAVE and GET, are provided for this purpose.
SAVE
Example 2-15 shows the SAVE command being used to save the contents of a 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.
Example 2-15. Writing the current buffer contents to a file
SQL>SELECT employee_name, project_name2FROM employee JOIN project_hours3ON employee.employee_id = project_hours.employee_id4JOIN project5ON project_hours.project_id = project.project_id6AND employee_billing_rate IN (7SELECT MAX(employee_billing_rate)8FROM employee)9GROUP BY employee_name, project_name10 SQL>SAVE highest_billed_emp_projectsCreated file highest_billed_emp_projects.sql
The SAVE command in Example 2-15 creates a new file, with the default extension of .sql, and writes the contents of the buffer to that file. After writing the buffer contents, SQL*Plus writes a trailing forward slash on a line by itself, so the resulting output file looks like this:
SELECT employee_name, project_name FROM employee JOIN project_hours ON employee.employee_id = project_hours.employee_id JOIN project ON project_hours.project_id = project.project_id ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access