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