数据库如何将表的某一列所有值用逗号隔开去重后合并成一行

listagg函数  【返回结果为varchar2格式的数据,即拼接后的字符串最大可以保存4000字节的数据】

SELECT
LISTAGG(student name,',')  WITHIN GROUP(ORDER BY student name)  listagg   FROM
student info t;

 

SELECT
t.student name,t.student sex   , LISTAGG(student name  ,','            WITHIN GROUP(ORDER BY student name)    OVER( PARTITION BY student sex)   listagg
FROM
student info t;

 

 xmlagg【当查询结果过长,拼接的字符串长度过长大于4000字节,我们可以使用这个函数,函数返回结果为CLOB类型,大对象数据类型最大可以存储4GB的数据长度。】

SELECT
xmlagg(xmlparse(content t.student name',’ WELLFORMED) order by t.student namlistagg
FROM
student info t;

 

xmlagg函数

select xmlagg(xmlparse(content 查询拼接字段 || ','wellformed) order by 排序字段).getclobval() as 查询显示字段
  from 表名 where 条件

 

posted @   KLAPT  阅读(31)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
点击右上角即可分享
微信分享提示