arrays - 等同于 Oracle 9i 中的 PostgreSQL array()/array_to_string() 函数

标签 arrays oracle postgresql

我希望从在 Oracle 中返回多行的查询中返回包含逗号分隔值列表的单行,实质上是将返回的行展平为单行。

在 PostgreSQL 中,这可以使用 array 和 array_to_string 函数来实现,如下所示:

给定表“people”:

id | name
---------
1  | bob
2  | alice
3  | jon

SQL:

select array_to_string(array(select name from people), ',') as names;

将返回:

names
-------------
bob,alice,jon

如何在 Oracle 9i 中获得相同的结果?

谢谢,

马特

最佳答案

Tim Hall 拥有权威收藏 string aggregation techniques in Oracle .

如果您坚持使用 9i,我个人的偏好是定义一个自定义聚合(该页面上有一个 string_agg 的实现)这样您就可以拥有

SELECT string_agg( name )
  FROM people

但是您必须定义一个新的 STRING_AGG 函数。如果您需要避免创建新对象,还有其他方法,但在 9i 中它们将比 PostgreSQL 语法更困惑。

关于arrays - 等同于 Oracle 9i 中的 PostgreSQL array()/array_to_string() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4326868/

相关文章:

java - 在 Wildfly 上部署 : ClassNotFoundException: Oracle12cDialect

sql - 如何导出 Oracle 统计信息

sql - 仅针对特定记录按子句分组

postgresql - Bugzilla - 表已经存在 : bz_schema at Bugzilla/DB/Schema. pm

ajax - 如何将 int 数组从 ajax 发送到 c# mvc?

c++ - 嵌套的 for_each 循环导致 vector 大小意外增加

sql - 在临时表中添加新列

ruby-on-rails - 如何在 Postgres 数据库中存储正则表达式或搜索词并在 Rails Query 中进行评估?

java - 从 JTable 中获取选定行的内容作为对象的 ArrayList

Python:拆分numpy数组