0

I am spooling a big result in a file but the spool add a lot of space between columns : one line is more than 6850 characters (mostly empty space), one column take 500 characters, for instance the first one :

 23053607                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            ;

Here is the query :

    spool result.txt;

    set pagesize 0
    set linesize 8000
    SET TRIMSPOOL ON
    set heading off
    set space 0
    set trimout off
    set termout off
    set verify off
    set echo off
    set feed off
    set trimspool on
    -- set echo off;
    -- set termout off;
    set colsep ';'
    set feedback off;
    set pages 0;
    spool result.txt;

    select 
    trim(rec.Code) AS Code,
    trim(A.label) AS Number,
    trim(B.text) AS Syst
    FROM record rec
    join tableA A on A.rec_id = rec.rec_id
    join tableB B on B.kla_id = rec.kla_id;

    spool off;

    exit; 

In the database there is no space. How to avoid any spaces ?

1
  • You may use SQLcl (SQL Developer command line) to simplyfy creation of CSV by specifying set sqlformat csv or by using /*+csv*/ hint. See the reference Commented Sep 2, 2022 at 7:32

1 Answer 1

1

Simplest thing to do is to just concatenate the values. Remove colsep and try out:

SELECT rec.Code ||';'||
       A.label  ||';'||
       B.text   
  FROM record rec
       JOIN tableA A ON A.rec_id = rec.rec_id
       JOIN tableB B ON B.kla_id = rec.kla_id;
Sign up to request clarification or add additional context in comments.

4 Comments

I get the error : ORA-00923: FROM keyword not found where expected
It's because of the AS clauses. IT's considered a single column. Try the adjusted. When you're spooling you will need to make a select for the header row.
Thanks you , but can I use aliases without "AS" ? rec.Code Code ||';'|| A.label number ||';'||
You can just do a dummy select from dual with the lines you want in your header: SELECT 'Code;Number;Syst' FROM dual, you already have SET HEAD OFF`. It solves the issue with the header, and there is no need to make aliases for the columns that way. It's all about what you have in the spool.

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.