数据库
首页 > 数据库> > oracle将多行字段拼接成一个列 (listagg函数)

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

 

 

 

 

 

 

标签:city,listagg,country,拼接,dual,oracle,GROUP,select
来源: https://www.cnblogs.com/Faith-zhang/p/16280961.html