SQLPLUS保存到文件 [英] SQLPLUS saving to file
问题描述
我必须对数据库类使用SQLPLUS,并且我们的第一个任务是简单保存.
I have to use SQLPLUS for my database class, and our first assignment is simple saving.
我按照说明进行了操作.(我正在使用PuTTY访问sqlplus)
I followed the instructions.. (I'm using PuTTY to access sqlplus)
在本练习中使用以下SQL命令,并尝试使用SAVE和SPOOL命令来保存SQL命令并输出到外部文件.
"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:
-
在SQL>提示符下,键入
Save test.sql
(如果文件已存在,则键入save test.sql replace
),然后按 enter ;然后键入任何SQL命令,这些命令将保存到test.sql文件.稍后,您可以使用START命令来运行保存的SQL命令.例如.: SQL>启动test.sql
At the SQL> prompt, type
Save test.sql
(orsave test.sql replace
if the file already exists) then hit enter; then type any SQL commands, the commands will be saved to the test.sql file. Later you can use the START command to run the saved SQL commands. E.g.: SQL> start test.sql
在SQL>提示符下,键入spool output.txt
,然后键入 enter ;然后键入任何SQL命令;完成后,键入"spool off";命令和结果将保存到文件output.txt.如果再次在spool命令中使用该文件,则该文件将被覆盖.在上课前的星期一,在D2L的投递箱中上交文件test.sql
和output.txt
."
At the SQL> prompt, type spool output.txt
then enter; then type any SQL commands; when finished type 'spool off'; the commands and results will be saved to file output.txt. The file will be overwritten if used in the spool command again. Turn in file test.sql
and output.txt
in the dropbox on D2L by Monday before class."
(显然,寻求帮助并不违反规则,因为说明已经正确了.我根本听不懂它们,或者它们错了)
(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)
当我输入SAVE test.sql时,我会产生=>没有什么可保存的"
When I type SAVE test.sql i yield => "Nothing to save"
当我在查询后键入SAVE test.sql时,它仅保存最后键入的查询.
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?
推荐答案
我如何保存所有查询而不是最后一个查询?
How do I have it save ALL my queries instead of just the last one typed?
SAVE将SQL * Plus缓冲区的内容保存到文件中.缓冲区将替换为您编写的每个SQL语句,因此仅获得最后一条命令.保存具有append
命令,该命令将追加到文件中.
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
并在每个SQL脚本之后附加文件.
and append the file after every SQL script.
select * from employees
/
save test.sql append;
select * from departments
/
save test.sql append;
以此类推
这篇关于SQLPLUS保存到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!