简体   繁体   English

如何在Oracle中后台处理查询结果

[英]How to spool query results in oracle

I am trying to print query result. 我正在尝试打印查询结果。 Here is the Oracle SQL Script: 这是Oracle SQL脚本:

set linesize 32767;
set pagesize 0; 
set newpage 0;
set space 0;
set echo off;
set feedback off;
set verify off;
set heading off;
set sqlprompt '';
set trimspool on;
set headsep off;

spool C:\asd.tmp
SELECT PROCESSNAME FROM ACTIVEPROCESSLIST ORDER BY PROCESSID;
spool off;

But the content of "asd.tmp" is that: 但是“ asd.tmp”的内容是:

SELECT PROCESSNAME FROM ACTIVEPROCESSLIST ORDER BY PROCESSID 从ACTIVEPROCESSLIST列表中按PROCESSID顺序选择PROCESSNAME

It prints just query text, not the result of it. 它仅打印查询文本,而不打印结果。 How can I spool query results? 如何假脱机查询结果?

NOTE: I am using "sqldeveloper-4.0.3.16.84-x64" and it runned as administrator. 注意:我正在使用“ sqldeveloper-4.0.3.16.84-x64”,它以管理员身份运行。 Also setting properties given above may be non-sense. 上面给出的设置属性也可能是无稽之谈。 I have tried some combinations of them and executing just spool commands without settings. 我尝试了它们的一些组合,并且只执行了后台处理命令而不进行设置。

Any other solution that I can execute in C++ is proper for me too. 我可以在C ++中执行的任何其他解决方案也都适合我。

you can use command line/sqlplus. 您可以使用命令行/ sqlplus。 try save your script as a file, then in command line: 尝试将脚本另存为文件,然后在命令行中:

    sqlplus -s [username]/[password]@[sid] @file_path > output.txt

There is an alternative way in that link . 该链接中有另一种方法。 I recommend it. 我推荐它。 It doesn't work as fast as spool solution but it works in my project at least. 它的工作速度不及后台打印解决方案,但至少在我的项目中有效。

There was a problem about the alternative way but the answer in this stackoverflow question works fine. 关于替代方法存在问题,但是此stackoverflow问题中的答案很好。 I am using it now. 我正在使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM