0

So I have a table that has a clob column. And sometimes I have multiple rows that I need to concatenate together which I do doing something like

Select n.textid 
LISTAGG(TRIM(n.text), '||')
WITHIN GROUP (ORDER BY n.createdate DESC) AS allnotes
from notetbl n 
GROUP BY n.noteid;

which gives me 99% of the data formatted as I want. But when the clob field has something like

this is the first line

this is the second

(two lines there is no white space in-between)

when exporting that data into excel or a csv file the second line adds a single double quotation mark to the end of the second line. Like this.

this is the first line

this is the second"

If I manually open the clob and shorten it to one line the " doesn't appear on the export. So is there a way to force all the clob data to be on one line? or somehow nothave that second quotation mark appear? thanks for any advice!

4
  • 1
    How are you exporting it? Which client/IDE/tool/command?
    – Alex Poole
    Commented Aug 15, 2024 at 18:34
  • @AlexPoole via the toad for oracle gui. Though i wrote a quick console app in C# to see if it was a Toad issue but got the same result Commented Aug 15, 2024 at 19:31
  • if you are using CSV you have to use double qoutation at the start and end of the column when exporting column data which has "special" characters. Show us your CSV file, open it in Notepad and paste the example here.
    – OracleDev
    Commented Aug 16, 2024 at 11:35
  • @OracleDev this is what a row that has the comment looks like Commented Aug 18, 2024 at 22:46

1 Answer 1

1

It looks to me like you have at the end of your text column a Chr(10) in some row(s).

--    S a m p l e    D a t a : 
Create Table notetbl (NOTEID Number(3), TEXTID VARCHAR2(3), text CLOB, CREATEDATE Date);
Insert Into notetbl Values ( 1, 'A', 'first line'  || Chr(10), TRUNC(Sysdate + 1));
Insert Into notetbl Values ( 2, 'A', 'second line', TRUNC(Sysdate));

... if you transform your query's resultset into csv (I work with Oracle SQL Developer where commented csv do the job)

Select /*csv*/ *
From   ( Select    n.noteid, 
                   LISTAGG(TRIM(n.text), '||') WITHIN GROUP (ORDER BY n.createdate DESC) AS allnotes
         From      notetbl n 
         Group By  n.noteid
       );

... result would be like :

"NOTEID","ALLNOTES"
1,"first line
"
2,"second line"

In Excel such a cell would have "Wrap Text" option ON.
If there is an unintentional Chr(10) character in the data, check the content of your text column to see if this is the case.

Select n.*
From   notetbl n 
Where  InStr(n.text, Chr(10)) > 0
/*
    NOTEID TEXTID TEXT            CREATEDATE
---------- ------ --------------  ----------
         1 A      first line      17.08.24    */

If this is the cause - get ridd of extra Char(10) characters...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.