Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLPlus settings to generate tab-separated data file

Anyone have a good set of sqlplus configuration directives to help transform a given sql query into nicely tab separated output for pulling into a spreadsheet or further processing?

like image 645
user19387 Avatar asked Sep 19 '08 23:09

user19387


People also ask

What is Trimspool in SQLPlus?

The TRIMSPOOL setting controls whether SQL*Plus writes trailing spaces when spooling data to a file. The default setting is OFF, which causes SQL*Plus to write each line to the spool file in its entirety, trailing spaces and all.


2 Answers

As Justin pointed out in his link, using the set colsep function SQLPlus command saves typing a separator for each column.

But for tab-delimited, set colsep Chr(9) won't work.

For UNIX or LINUX, use set colsep ' ' with the space between the single-quotes being a typed tab.

For Windows, use these settings:

col TAB# new_value TAB NOPRINT
select chr(9) TAB# from dual;
set colsep "&TAB"

select * from table;
like image 80
user158017 Avatar answered Sep 20 '22 15:09

user158017


One particular script that I have stolen on more than one occasion comes from an AskTom thread on extracting data to a flat file. If I needed a quick and dirty flat file out of SQL*Plus. I would tend to prefer the DUMP_CSV function Tom posted earlier on that thread for any sort of ongoing process, though.

like image 35
Justin Cave Avatar answered Sep 19 '22 15:09

Justin Cave