简体   繁体   中英

How to spool query results in oracle

I am trying to print query result. Here is the Oracle SQL Script:

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:

SELECT PROCESSNAME FROM ACTIVEPROCESSLIST ORDER BY PROCESSID

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. 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.

you can use command line/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. I am using it now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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