oracle分组查询,获取组内所有信息(拼接显式)


使用listagg函数实现

语法结构

listagg(measure_expr,delimiter) within group ( order by order_by_clause);

解释:measure_expr可以是基于任何列的表达式

  delimiter分隔符,默认为NULL

  order_by_clause决定了列值的拼接顺序

 

举例

create table emp1(s1 number, s2 number);
insert into emp1 values(1,1);
insert into emp1 values(1,2);
insert into emp1 values(1,3);
insert into emp1 values(2,4);
insert into emp1 values(2,5);


select s1, listagg(s2,',')within group(order by s2) name from emp1 group by s1;
select listagg(s2,',')within group(order by s1)name from emp1;

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM