oracle将多行字段拼接成一个列 (listagg函数)

1、基本语法

将多行同列合并展示为一行:LISTAGG(展示字段,分隔符) WITHIN GROUP( ORDER BY 分组维度)

2、解析

with temp as(
select '中国' country ,'北京' city from dual 
union all
select '中国' country ,'深圳' city from dual 
union all
select '中国' country ,'上海' city from dual 
)
select country,listagg(city,',') within GROUP (order by country) as brands
from temp
group by country

 

 

 

 

 

 

posted @ 2022-05-17 15:20  Faith_zhang  阅读(3643)  评论(1编辑  收藏  举报