sqloracle-databasesshsqlplus

SQLPLUS saving to file


I have to use SQLPLUS for my database class, and our first assignment is simple saving.

I followed the instructions.. (I'm using PuTTY to access sqlplus)

"Use the following SQL commands in this exercise and try the SAVE and SPOOL commands to save your SQL commands and output to external files.

select table_name from all_tables where owner='UNIVERSITY';
select * from university.faculty;
select * from university.clubs;

For this lab, do the following:

(Obviously asking for help isn't against the rules, since the instructions are right there already.. i simply don't understand them or they're wrong)

When I type SAVE test.sql i yield => "Nothing to save"

When I type SAVE test.sql after a query, it saves only the last typed query.

How do I have it save ALL my queries instead of just the last one typed?


Solution

  • How do I have it save ALL my queries instead of just the last one typed?

    SAVE saves the content of the SQL*Plus buffer into the file. The buffer gets replaced with every SQL statement that you write, hence you get only the last command. Save has an append command that will append to the file.

    So, first create your file.

    save test.sql create
    

    and append the file after every SQL script.

    select * from employees
    /
    save test.sql append;
    select * from departments
    /
    save test.sql append;
    

    and so on