How to output oracle sql result into a file in windows?

Dreamer picture Dreamer · Mar 6, 2013 · Viewed 218.2k times · Source

I tried

select * from users 
save D:\test.sql create;

But SQL plus gives me "no proper ended" How to specify path in oracle sql in windows?

Answer

Marc picture Marc · Mar 6, 2013

Use the spool:

spool myoutputfile.txt
select * from users;
spool off;

Note that this will create myoutputfile.txt in the directory from which you ran SQL*Plus.

If you need to run this from a SQL file (e.g., "tmp.sql") when SQLPlus starts up and output to a file named "output.txt":

tmp.sql:

select * from users;

Command:

sqlplus -s username/password@sid @tmp.sql > output.txt

Mind you, I don't have an Oracle instance in front of me right now, so you might need to do some of your own work to debug what I've written from memory.