Saving SQLPLUS to a file

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

I followed the instructions .. (I use 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; 

In this lab, do the following:

  • At the SQL command line> type Save test.sql (or save test.sql replace if the file already exists), press enter ; then enter any SQL commands, the commands will be saved in the test.sql file. Later, you can use the START command to run the saved SQL commands. For example: SQL> start test.sql

  • At the SQL command prompt> type spool output.txt , then enter ; then enter any SQL commands; when the type "spool off" is finished; commands and results will be saved to output.txt file. The file will be overwritten if it is used again in the spool command. Include test.sql and output.txt in Dropbox on D2L until Monday before the class. "

(Obviously, the request for help does not contradict the rules, since there are already instructions there .. I just don’t understand them or they’re wrong)

When I print SAVE test.sql I yield => "Save nothing"

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

How do I save all my queries, not just the last ones printed?

+4
source share
1 answer

How do I save all my queries, not just the last ones printed?

SAVE saves the contents of the SQL * Plus buffer to a file. The buffer is replaced with every SQL statement that you write, so you only get the last command. Save has an append command that will be added to the file.

So first create your file.

 save test.sql create 

and add the file after each SQL script.

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

etc.

+5
source

Source: https://habr.com/ru/post/1392397/


All Articles