在11G以下版本中oracle有自帶的函數wm_concat可以實現,如:
select wm_concat(id) from table where col='1'
但是在12C版本中此函數無法使用,但可以使用另一種方式實現,如:
select xmlagg(xmlparse(content upper(id)||',' wellformed) order by id).getclobval() from table where col='1'
該函數返回結果為一個Blob類型的大字段,且因為使用逗號拼接的關系,在結尾會多一個逗號,轉換為字符串后會默認全部大寫,如不需要大寫可以自己修改函數或轉換。