oracle 将 sqlplus 输出写入文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15984946/
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
Writing sqlplus output to a file
提问by
Using sqlplus.exe I'm looking for a way to write sqlplus output to a file.
使用 sqlplus.exe 我正在寻找一种将 sqlplus 输出写入文件的方法。
Is there anyway I can do that, currently the output is written only to the console.
无论如何我可以做到这一点,目前输出仅写入控制台。
回答by
You may use the SPOOL command to write the information to a file.
您可以使用 SPOOL 命令将信息写入文件。
Before executing any command type the following:
在执行任何命令之前键入以下内容:
SPOOL <output file path>
All commands output following will be written to the output file.
以下所有命令输出都将写入输出文件。
To stop command output writing type
停止命令输出写入类型
SPOOL OFF
回答by Ed Gibbs
Also note that the SPOOL
output is driven by a few SQLPlus settings:
另请注意,SPOOL
输出由一些 SQLPlus 设置驱动:
SET LINESIZE nn
- maximum line width; if the output is longer it will wrap to display the contents of each result row.SET TRIMSPOOL OFF|ON
- if setOFF
(the default), every output line will be padded toLINESIZE
. If setON
, every output line will be trimmed.SET PAGESIZE nn
- number of lines to output for each repetition of the header. If set to zero, no header is output; just the detail.
SET LINESIZE nn
- 最大线宽;如果输出更长,它将换行以显示每个结果行的内容。SET TRIMSPOOL OFF|ON
- 如果设置OFF
(默认),每个输出行将被填充到LINESIZE
. 如果设置ON
,则每条输出行都将被修剪。SET PAGESIZE nn
- 标题的每次重复输出的行数。如果设置为零,则不输出标题;只是细节。
Those are the biggies, but there are some others to consider if you just want the output without all the SQLPlus chatter.
这些都是大问题,但是如果您只想要输出而不需要所有 SQLPlus 喋喋不休,还有其他一些需要考虑。
回答by Gujju
Make sure you have the access to the directory you are trying to spool. I tried to spool to root and it did not created the file (e.g c:\test.txt
). You can check where you are spooling by issuing spool
command.
确保您有权访问要假脱机的目录。我试图假脱机到 root 并且它没有创建文件(例如c:\test.txt
)。您可以通过发出spool
命令来检查您正在假脱机的位置。
回答by hello_earth
just to save my own deductions from all this is (for saving DBMS_OUTPUT output on the client, using sqlplus):
只是为了保存我自己对所有这些的推断(用于在客户端保存 DBMS_OUTPUT 输出,使用 sqlplus):
- no matter if i use Toad/with polling or sqlplus, for a long running script with occasional dbms_output.put_line commands, i will get the output in the end of the script execution
- set serveroutput on; and dbms_output.enable(); should be present in the script
- to save the output SPOOL command was not enough to get the DBMS_OUTPUT lines printed to a file - had to use the usual > windows CMD redirection. the passwords etc. can be given to the empty prompt, after invoking sqlplus. also the "/" directives and the "exit;" command should be put either inside the script, or given interactively as the password above (unless it is specified during the invocation of sqlplus)
- 无论我使用 Toad/with polling 还是 sqlplus,对于偶尔使用 dbms_output.put_line 命令的长时间运行的脚本,我都会在脚本执行结束时获得输出
- 设置服务器输出;和 dbms_output.enable(); 应该出现在脚本中
- 保存输出 SPOOL 命令不足以将 DBMS_OUTPUT 行打印到文件中 - 必须使用通常的 > windows CMD 重定向。调用 sqlplus 后,可以将密码等提供给空提示。还有“/”指令和“exit”;命令应该放在脚本中,或者作为上面的密码交互地给出(除非它在调用 sqlplus 期间指定)