我选择了这样的查询; 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中实现这一目标?
答案 0 :(得分:4)
请尝试以下查询,该问题适用于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