Skip to Main Content
  • Questions
  • Directing a select query output to a text file

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Granger.

Asked: March 02, 2016 - 9:58 am UTC

Last updated: March 02, 2016 - 3:51 pm UTC

Version: Latest

Viewed 10K+ times! This question is

You Asked

select * from table;


This is my query in SQL Plus.
I need the exact output of this query into a text file.
I tried SPOOL Command but it prints entire screen in the text file.
Please help me with this.

and Chris said...

You may find this easier with SQL Developer/SQLcl. These come with formatting comments controlling how they display output. e.g.:

select /*csv*/ from ...
select /*xml*/ from ...


For more info, see:

http://www.thatjeffsmith.com/archive/2012/05/formatting-query-results-to-csv-in-oracle-sql-developer/
http://www.thatjeffsmith.com/archive/2015/12/more-set-sqlformat-fun-in-sqlcl/

Is this answer out of date? If it is, please let us know via a Comment