Oracle SQL Developer 3.1.07 extra spaces between characters using listagg
are you using UTF-16
+ NVARCHAR2
by any chance? eg this:
SQL> select * from nls_database_parameters where parameter='NLS_NCHAR_CHARACTERSET';
PARAMETER VALUE
------------------------------ ----------------------------------------
NLS_NCHAR_CHARACTERSET AL16UTF16
SQL> drop table test;
Table dropped.
SQL> create table test(a nvarchar2(10));
Table created.
SQL> insert into test values ('test');
1 row created.
SQL> insert into test values ('test 2');
1 row created.
SQL> select listagg(a, ',') within group (order by 1) from test group by 1;
LISTAGG(A,',')WITHINGROUP(ORDERBY1)
--------------------------------------------------------------------------------
t e s t, t e s t 2
you could cast to a char to get round this. IF this is not acceptible, you need to raise a ticket with Oracle support.
SQL> select listagg(to_char(a),',') within group (order by 1) from test group by 1;
LISTAGG(TO_CHAR(A),',')WITHINGROUP(ORDERBY1)
--------------------------------------------------------------------------------
test,test 2
SQL>
This is currently a known bug with no fix:
Bug 13501087 11.2.0.3 RDBMS 11.2.0.3 SQL EXECUTION PRODID-5 PORTID-226
Abstract: LISTAGG RETURN STRANGE DATA
*** 12/14/11 05:12 am *** (ADD: Impact/Symptom->WRONG RESULTS )
SubComponent: SQL Analytics
===========================
DETAILED PROBLEM DESCRIPTION
============================
When using LISTAGG function with NVARCHAR , data is returned with spaces
between characters
On Oracle 12c I had the issue to with LISTAGG
function. I used
ASCIISTR()
to get around it:
SELECT LISTAGG(TRIM(ASCIISTR(NVL(Name,''))), ';')
WITHIN GROUP (ORDER BY NAME) AS Names
Works fine over here.