简体   繁体   English

Oracle SQL Developer 3.1.07使用listagg在字符之间留出额外空格

[英]Oracle SQL Developer 3.1.07 extra spaces between characters using listagg

I am using SQL Developer 3.1.07 on an 11g database When I use listagg to extract multiple values from a field I get a space between each character in the results for the listagg column. 我在11g数据库上使用SQL Developer 3.1.07当我使用listagg从字段中提取多个值时,我在listagg列的结果中的每个字符之间得到一个空格。 The query returns all the values I expect to see, it's just the extra spaces that are driving me nuts. 查询返回我期望看到的所有值,它只是让我疯狂的额外空格。 Any thoughts? 有什么想法吗?

Here is one query that I have used, but it happens everytime I use listagg in a query: 这是我使用过的一个查询,但每次在查询中使用listagg时都会发生这种情况:

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;

Here are the results I get: 以下是我得到的结果:

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

are you using UTF-16 + NVARCHAR2 by any chance? 你有机会使用UTF-16 + NVARCHAR2吗? 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. 如果这不可接受,您需要提供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>

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 错误13501087 11.2.0.3 RDBMS 11.2.0.3 SQL执行PRODID-5 PORTID-226

Abstract: LISTAGG RETURN STRANGE DATA 摘要:LISTAGG返回STRANGE数据

*** 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. 在Oracle 12c上,我遇到了LISTAGG功能的问题。 I used ASCIISTR() to get around it: 我使用ASCIISTR()来解决它:

SELECT LISTAGG(TRIM(ASCIISTR(NVL(Name,''))), ';') 
WITHIN GROUP (ORDER BY NAME) AS Names 

Works fine over here. 在这里工作得很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM