假脱机命令:不将SQL语句输出到文件 [英] Spool Command: Do not output SQL statement to file
问题描述
我想将查询输出到CSV文件,并将以下内容用作小测试;
I am wanting to output a Query to a CSV file and am using the below as a small test;
spool c:\test.csv
select /*csv*/ username, user_id, created from all_users;
spool off;
但是输出的实际选择语句为第一行
but the output has the actual select statment as the first line
> select /*csv*/ username user_id created from all_users
USERNAME USER_ID CREATED
REPORT 52 11-Sep-13
WEBFOCUS 51 18-Sep-12
有没有办法防止这种情况?我尝试过SET Heading Off,但认为并没有改变.我正在使用SQL Developer作为脚本运行.
Is there a way to prevent this? I tried SET Heading Off thinking that might do it, but it did not change. I am using SQL Developer an running as script.
谢谢 布鲁斯
推荐答案
不幸的是,SQL Developer没有完全接受set echo off
命令,该命令会(似乎)在SQL * Plus中解决此问题.
Unfortunately SQL Developer doesn't fully honour the set echo off
command that would (appear to) solve this in SQL*Plus.
我为此找到的唯一解决方法是将您正在做的事情保存为脚本,例如test.sql
带有:
The only workaround I've found for this is to save what you're doing as a script, e.g. test.sql
with:
set echo off
spool c:\test.csv
select /*csv*/ username, user_id, created from all_users;
spool off;
然后从SQL Developer中仅调用该脚本:
And then from SQL Developer, only have a call to that script:
@test.sql
然后将其作为脚本(F5)运行.
And run that as a script (F5).
除临时查询外,另存为脚本文件并不难.并使用@
运行该脚本,而不是直接打开脚本并直接运行它,只是有点麻烦.
Saving as a script file shouldn't be much of a hardship anyway for anything other than an ad hoc query; and running that with @
instead of opening the script and running it directly is only a bit of a pain.
稍作搜索后,在 SQL Developer论坛和开发团队中找到了相同的解决方案建议模仿SQL * Plus的行为是故意行为;您也需要在其中使用@
运行脚本以隐藏查询文本.
A bit of searching found the same solution on the SQL Developer forum, and the development team suggest it's intentional behaviour to mimic what SQL*Plus does; you need to run a script with @
there too in order to hide the query text.
这篇关于假脱机命令:不将SQL语句输出到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!