1、wmsys.wm_concat
Oracle中的wmsys.wm_concat主要實現行轉列功能(說白了就是將查詢的某一列值使用逗號進行隔開拼接,成爲一條數據)。
2、LISTAGG
這是最基礎的用法:
LISTAGG(XXX,XXX) WITHIN GROUP( ORDER BY XXX)
用法就像聚合函數一樣,通過Group by語句,把每個Group的一個字段,拼接起來。
非常方便。
同樣是聚合函數,還有一個高級用法:
就是over(partition by XXX)
也就是說,在你不實用Group by語句時候,也可以使用LISTAGG函數:
3、實例:
select t1.jsbh,t.* from t_auth_user t,t_auth_user_role t1 where t.yhbh=t1.yhbh order by t.yhbh,t1.jsbh ;
select t.yhbh,listagg(jsbh,',') within GROUP (order by jsbh) js
from t_auth_user t,t_auth_user_role t1
where t.yhbh=t1.yhbh
group by t.yhbh ;
select t.yhbh,wm_concat(t.jsbh) as js from t_auth_user_role t group by t.yhbh ;