当前位置:   article > 正文

oracle listagg函数讲讲

listagg

listagg是oracle11.2增加的特性。

功能类似wmsys.wm_concat函数,即将数据分组后,把指定列的数据通过指定符号合并。

--listagg()函数,列转行。 在每个分组内,LISTAGG根据order by子句对列值进行排序,将排序后的结果拼接起来。

--基本语法;listagg(待处理列,连接符号) within group(order by 用于拼接组内排序字段)

select a.* from test_userinfo a;

--分组函数:

select a.user_sex,listagg(a.user_school,',') within group(order by a.user_age) from test_userinfo a group by a.user_sex;

--分析函数:根据年龄分区,在分区内部拼接学校,然后拼接时按照性别排序

select a.user_name,a.user_age,a.user_school,listagg(a.user_school,',') within group(order by a.user_sex) over (partition by a.user_age) from test_userinfo a;

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/591345
推荐阅读
相关标签
  

闽ICP备14008679号