0

I am using this script as below

set colsep ','
set heading on
set headsep on
set pagesize 0
set trimspool off
spool C:\DXC\books11.csv
Select * from test_extract;
spool off
exit

but the problem with this is

ARKO                ,1A                  ,        20
ARKO1               ,1B                  ,        20

space is comming after the values of each attribute as per the lenght of the attribute.

required output :

ARKO,1A,20
ARKO1,1B,20
2
  • 1
    If you have access to sql developer, then it is as simple as select /*csv*/ * from t; https://www.thatjeffsmith.com/archive/2012/05/formatting-query-results-to-csv-in-oracle-sql-developer/ Commented May 8, 2020 at 20:06
  • Are those CHAR or VARCHAR2 columns? Commented May 8, 2020 at 22:24

2 Answers 2

1

As far as I can tell, no SET command will help.

One option - that helps - is to name all columns you're spooling and concatenate them using desired column separator.

For example, this is what you currently have:

SQL> set colsep ','
SQL> set heading on
SQL> set headsep on
SQL> set pagesize 0
SQL> set trimspool off
SQL> select * From dept;
        10,ACCOUNTING    ,Zagreb
        20,RESEARCH      ,DALLAS
        30,SALES         ,CHICAGO
        40,OPERATIONS    ,BOSTON

But, if you do it as follows:

SQL> select deptno ||','|| dname ||','|| loc from dept;
10,ACCOUNTING,Zagreb
20,RESEARCH,DALLAS
30,SALES,CHICAGO
40,OPERATIONS,BOSTON

it looks as you wanted. Drawback? You'll have to type all those columns.

Sign up to request clarification or add additional context in comments.

Comments

0

Use SQLcl, it's in your SQL Developer bin directory, works like SQLPlus, only better.

It's SQL.exe on Windows for example, but also available as it's own 25mb download on Oracle.com.

set sqlformat csv
spool file.csv
select * from table;

It'll give you exactly what you're asking for.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.