SQL SQLPLUS 保存到文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8966577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQLPLUS saving to file
提问by Sterling Archer
I have to use SQLPLUS for my database class, and our first assignment is simple saving.
我的数据库类必须使用 SQLPLUS,我们的第一个任务是简单的保存。
I followed the instructions.. (I'm using PuTTY to access sqlplus)
我按照说明..(我使用 PuTTY 访问 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.
“在本练习中使用以下 SQL 命令,并尝试使用 SAVE 和 SPOOL 命令将 SQL 命令和输出保存到外部文件。
select table_name from all_tables where owner='UNIVERSITY';
select * from university.faculty;
select * from university.clubs;
For this lab, do the following:
对于本实验,请执行以下操作:
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.sqlAt 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 filetest.sql
andoutput.txt
in the dropbox on D2L by Monday before class."
在 SQL> 提示符下,输入
Save test.sql
(或者save test.sql replace
如果文件已经存在)然后点击enter; 然后键入任何 SQL 命令,这些命令将保存到 test.sql 文件中。稍后您可以使用 START 命令运行保存的 SQL 命令。例如:SQL> 启动 test.sql在 SQL> 提示符下,键入
spool output.txt
then enter; 然后键入任何 SQL 命令;完成后键入“线轴关闭”;命令和结果将保存到文件 output.txt。如果再次用于 spool 命令,该文件将被覆盖。周一上课前在 D2L 上提交文件test.sql
和output.txt
保管箱。”
(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"
当我输入 SAVE test.sql 时,我屈服 => “没什么可保存的”
When I type SAVE test.sql after a query, it saves only the last typed query.
当我在查询后输入 SAVE test.sql 时,它只保存最后输入的查询。
How do I have it save ALL my queries instead of just the last one typed?
我如何让它保存我所有的查询,而不是只保存最后一个输入的查询?
采纳答案by Sathyajith Bhat
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.
SAVE 将 SQL*Plus 缓冲区的内容保存到文件中。缓冲区会被您编写的每条 SQL 语句替换,因此您只能获得最后一条命令。Save 有一个append
命令可以附加到文件中。
So, first create your file.
所以,首先创建你的文件。
save test.sql create
and append the file after every SQL script.
并在每个 SQL 脚本之后附加该文件。
select * from employees
/
save test.sql append;
select * from departments
/
save test.sql append;
and so on
等等