之前有在 MySQL 用過這個需求用過這個需求GROUP_CONCAT 和 CONCAT_WS 多個橫欄和縱欄組在一起方法 | 程式狂想筆記
但是 Oracle 用上有差異
還多了一堆限制(如:字數不能超過 4000)
distinct 還會被禁用??!
Distinct
- Oracle listagg去重distinct三種方法總結_weixiaohuai的博客-CSDN博客
- Remove Duplicates From Comma Separated String — oracle-tech
1 | -- 此方法需要排序後才有過濾重複效果 |
字數過長
1 | SQL> select rtrim(xmlagg(xmlelement(e,id,',').extract('//text()') order by id).GetClobVal(),',') |
但這個沒有排序…
逗號排序
Sort delimited separated values in a string with (Oracle) SQL - Stack Overflow
1 | select listagg(somedata, '|') within group (order by somedata) somedata from ( |
但這個跟 xmlagg 結合會有問題
都會跑出 null
先記錄到這邊