Dreamer Dreamer - 7 months ago 34
SQL Question

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

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?


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":


select * from users;


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.