Oracle中添加逗号(,)
给出以下查询:
select distinct subject_key
from mytable
结果:
subject_key
-----------
90896959
90895823
90690171
90669265
90671321
我如何在 Oracle 中编写查询(使用 Aqua Data Studio 后端 Oracle 8i) 结果:
subject_key
-----------
90896959,
90895823,
90690171,
90669265,
90671321
谢谢大家! 我是否希望将输出更改为横向而不是向下,如下所示。怎么写啊,同一个平台。谢谢。
subject_key
90896959, 90895823, 90690171, 90669265, 90671321
Given this query:
select distinct subject_key
from mytable
Result:
subject_key
-----------
90896959
90895823
90690171
90669265
90671321
How do i write a query in Oracle (using Aqua Data Studio backend Oracle 8i) result:
subject_key
-----------
90896959,
90895823,
90690171,
90669265,
90671321
THANKS ALL!
Should I wish to change the output across instead of down like below. How do I write it, same platform. Thanks.
subject_key
90896959, 90895823, 90690171, 90669265, 90671321
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Oracle 没有像 MySQL 的 GROUP_CONCAT 这样的功能,而这正是您所要求的功能。 此页面提供了此类字符串聚合的各种选项 - 一种是使用自定义函数:
然后您可以像这样使用它:
...替换“?”与主键值。
以前
假设您只想在列值末尾添加逗号,请使用:
双管道 --“||” -- 是 Oracle [、PostgreSQL 和现在的 ANSI] 在 SQL 中连接字符串的方法。我使用 TO_CHAR 显式转换数据类型,但您可以使用:
...如果没有必要。
Oracle doesn't have a function like MySQL's GROUP_CONCAT, which is exactly the functionality you're asking for. Various options for such string aggregation are provided on this page - one is to use a custom function:
Then you'd use it like:
...replacing the "?" with the primary key value.
Previously
Assuming you just want to add a comma to the end of the column value, use:
The double pipe -- "||" -- is the Oracle [,PostgreSQL and now ANSI] means of concatenating strings in SQL. I used TO_CHAR to explicitly convert the data type, but you could use:
...if that's not necessary.
最有可能的是: SELECT subject_key + ',' AS subject_key FROM mytable
至少在 T-SQL 中是这样的。 PL-SQL 可能略有不同。
most likely: SELECT subject_key + ',' AS subject_key FROM mytable
At least that's how in T-SQL. PL-SQL may be slightly different.