Aggregate String Concatenation in Oracle 10g [duplicate]

我们两清 提交于 2019-11-29 11:29:39

It is easy on 11G, you can use the LISTAGG function, but sadly not on 10G

There are some techniques here for earlier versions however they do require a function to be written.

http://www.oracle-base.com/articles/misc/string-aggregation-techniques.php

Try this query

select No  , rtrim(Name,',') Name
   from ( select No , Name , rn from yourtable
           model
  partition by (No)
  dimension by (row_number() over
 (partition by No order by Name) rn
 )
 measures  (cast(Name as varchar2(40)) Name)
   rules
 ( Name[any] order by rn desc = Name[cv()]||' '||Name[cv()+1]
   )
  )
    where rn = 1
    order by NO

Here is your sql demo

you can use LISTAGG

see demo here

Try this SQL query

SELECT 
  [No],
  STUFF((
    SELECT ' ' + Name
    FROM #tbl_concat 
    WHERE ([No] = Results.[No]) 
    FOR XML PATH (''))
  ,1,0,'') AS NameValues
FROM #tbl_concat Results
GROUP BY [No] 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!