oracle里的listagg,oracle中的listagg函数

listagg()用于字符串聚集

LISTAGG(XXX--要合并的列,XXX--分隔符) WITHIN GROUP( ORDER BY XXX) over(partition by XXX)

需要注意的事项如下:

1. 必须得分组,也就是说group  by是必须的。

2. listagg函数的第一个参数是需要进行合并的字段;第二个参数是分隔符;同时还需要进行排序和分组within group (order by XXX)

eg:

(1)LISTAGG(XXX--要合并的列,XXX--分隔符) WITHIN GROUP( ORDER BY XXX)

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)

<

你可能感兴趣的:(oracle里的listagg)