2013-03-08 19 views
8

Sto utilizzando SQL Developer 3.1.07 su un database 11g Quando uso listagg per estrarre più valori da un campo ottengo uno spazio tra ogni carattere nei risultati per la colonna listagg. La query restituisce tutti i valori che mi aspetto di vedere, sono solo gli spazi extra che mi stanno facendo impazzire. qualche idea?Oracle SQL Developer 3.1.07 spazi aggiuntivi tra caratteri utilizzando listagg

Qui è una query che ho usato, ma succede ogni volta che uso listagg in una query:

select a.personnum Emp_ID 
     , a.personfullname Name 
     , a.companyhiredtm Hire_Date 
     , a.employmentstatus Status 
     , a.employmentstatusdt Status_Date 
     , h.Supervisor, h.Agency 
from vp_employeev42 a 
    left outer join (select f.personid 
          , listagg (g.personcstmdatatxt, ',') within group 
           (order by g.customdatadefid) Supervisor 
        from vp_employeev42 f 
        left outer join personcstmdata g 
         on f.personid = g.personid 
        where f.personnum like 'T%' 
        and f.homelaborlevelnm3 = '1872' 
        and (g.customdatadefid = '1' 
          or g.personcstmdatatxt is null) 
        group by f.personid) h 
      on a.personid = h.personid 
    left outer join (select f.personid 
         , listagg (g.personcstmdatatxt, ',') 
           within group (order by g.customdatadefid) Agency 
        from vp_employeev42 f 
        left outer join personcstmdata g 
          on f.personid = g.personid 
        where f.personnum like 'T%' 
        and homelaborlevelnm3 = '1872' 
        and (g.customdatadefid = '3' 
           or g.personcstmdatatxt is null) 
         group by f.personid) h 
     on a.personid = h.personid 
where personnum like 'T%' 
and homelaborlevelnm3 = '1872' 
order by personnum; 

Ecco i risultati che ottengo:

EMP_ID,NAME,HIRE_DATE,STATUS,STATUS_DATE,SUPERVISOR,AGENCY 
T98999,Lxxxxm, Lxxxn,20-SEP-12,Active,20-SEP-12,, S t a f f m a r k 

T98989,Fxxxxn, Dxxxxa,10-DEC-12,Active,10-DEC-12,, S t a f f m a r k 

T99989,Hxxxs, Cxxxxxa,02-OCT-12,Active,02-OCT-12,, S t a f f m a r k 
T99999,Hxxxs, Dxxxn,30-JAN-12,Terminated,21-MAY-12, C x x x x x x x x x r T x x x x r, P R O L O G I S T I X 
+0

In futuro, si prega di inviare un * piccolo caso di test riproducibile * invece di un enorme pezzo di codice difficile da capire. A parte ogni altra cosa, l'atto di far bollire un problema fino al suo essenziale spesso fornisce la soluzione, che è il modo migliore per imparare. – APC

risposta

13

stai usando UTF-16 + NVARCHAR2 per caso? Ad esempio:

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 

si può trasmettere a un carattere per aggirare questo. Se questo non è accettabile, è necessario aumentare un ticket con il supporto Oracle.

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> 
+0

Questo era il trucco, sto usando UTF-16 + NVARCHAR2 e l'ho usato con to_char. Grazie mille per l'aiuto. –

5

Questo è attualmente un bug noto con alcuna correzione:

Bug 13.501.087 11.2.0.3 RDBMS SQL 11.2.0.3 ESECUZIONE PRODID-5 portid-226

Abstract: LISTAGG RETURN STRANGE DATI

*** 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 
Problemi correlati