通常,WM_CONCAT是一个聚合函数,它返回表中用逗号分隔的值,就像这里一样.
假设我有一个像这样的表foo:
col_id | col_text 111 | This 111 | is 111 | a 111 | test.
如果我使用此查询:
SELECT CAST(WM_CONCAT(col_text) AS VARCHAR2(100)),col_id FROM foo
结果将是
This,is,a,test.
是否可以将分隔符(‘,’)更改为其他字符,如’.’或’|’ WM_CONCAT()函数?
解决方法
您可能想要使用
LISTAGG
.
SELECT col_id,LISTAGG(col_text,'|') WITHIN GROUP (ORDER BY col_text) text FROM table1 GROUP BY col_id
输出:
| COL_ID | TEXT | ---------------------------- | 111 | This|a|is|test. |
更新如果您需要在列表中获取不同的文本值
SELECT col_id,'|') WITHIN GROUP (ORDER BY col_text) text FROM ( SELECT DISTINCT col_id,col_text FROM table1 ) GROUP BY col_id