我有这样的选择查询;select id, email from operators where op_code = 1
查询结果如下;
ID EMAIL
-- -----
1 abc@abc.com
2 xyz@xyz.com
3 def@def.com
但我想要这种格式的电子邮件,abc@abc.com,xyz@xyz.com,def@def.com
如何在 Oracle 中实现这一点?
Please try below query, which works in ORACLE 11G:
select
listagg(email, ',')
within group (order by id) as list
from operators
where op_code=1
OR
SELECT
(RTRIM(XMLAGG(xmlelement(X, EMAIL||',')order by id).extract('//text()'),',')) list
FROM operators
WHERE op_code=1