在 Oracle 中将 SQL 行转换为逗号分隔值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9089837/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Transform SQL Rows into Comma-Separated values in Oracle
提问by Ianthe
Possible Duplicate:
How can I combine multiple rows into a comma-delimited list in Oracle?
How can you produce a comma-separated values from list of return rows in SQL without creating a function? Need to remove duplicates and null or with 'None' as the value.
如何在不创建函数的情况下从 SQL 中的返回行列表生成逗号分隔的值?需要删除重复项和 null 或以 'None' 作为值。
Example: select name from student;
例子: select name from student;
The result :
结果 :
NAME
------
Zed
Charlo
None
Charlo
Dionn
Ansay
Desired output :
所需的输出:
Name
-------
Zed,Charlo,Dionn,Ansay
回答by Jake Feasel
http://sqlfiddle.com/#!4/9ad65/2
http://sqlfiddle.com/#!4/9ad65/2
select
listagg(name, ',')
within group (order by id) as list
from student