Oracle行转列函数Listagg()、wm_concat
-
Oracle行专列函数Listagg()、wm_concat
说明:函数可以把列值以","号分隔起来,并显示成一行
with temp as(
select 'China' nation ,'Guangzhou' city from dual union all
select 'China' nation ,'Shanghai' city from dual union all
select 'China' nation ,'Beijing' city from dual union all
select 'USA' nation ,'New York' city from dual union all
select 'USA' nation ,'Bostom' city from dual union all
select 'Japan' nation ,'Tokyo' city from dual
)
select nation,listagg(city,',') within GROUP (order by city)
from temp
group by nation-- (通用写法 )
-- select nation,wm_concat(city) from temp group by nation(12c 之前的测试 函数,用于12c 之前)
这是最基础的用法:
LISTAGG(XXX,XXX) WITHIN GROUP( ORDER BY XXX)
转换前:
转换后:
原文链接:http://www.jxszl.com/biancheng/shujuku/445416.html