Oracle视图分组元素
嗨,
这是我的问题...
我有一个表:
+------+------+------+
| CODE | NAME | TYPE |
+------+------+------+
| 1 | AAA | x |
+------+------+------+
| 2 | BBB | x |
+------+------+------+
| 3 | CCC | y |
+------+------+------+
| 4 | DDD | y |
+------+------+------+
我想在 ORACLE 中创建一个视图...我想要结果是:
+---------+------+
| NAME | TYPE |
+---------+------+
| AAA;BBB | x |
+---------+------+
| CCC;DDD | y |
+---------+------+
我可以对 AAA 进行分组吗和 BBB,因为它们在视图中具有相同的类型,在名称中将为“AAA;BBB”...因此将各种名称除以 ; 进行分组
有人可以帮助我吗?
问候,
托马索
Possible Duplicate:
Oracle: Combine multiple results in a subquery into a single comma-separated value
Hi there,
this is my problem...
I have a table:
+------+------+------+
| CODE | NAME | TYPE |
+------+------+------+
| 1 | AAA | x |
+------+------+------+
| 2 | BBB | x |
+------+------+------+
| 3 | CCC | y |
+------+------+------+
| 4 | DDD | y |
+------+------+------+
I wanna make a view in ORACLE .... I wanna that the result is:
+---------+------+
| NAME | TYPE |
+---------+------+
| AAA;BBB | x |
+---------+------+
| CCC;DDD | y |
+---------+------+
Can I grouping AAA and BBB because they have same TYPE in a VIEW that in a NAME will be "AAA;BBB" ... so grouping various names divided with ;
Can anyone help me?
Regards,
Tommaso
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Tim Hall 的一个页面涵盖了 Oracle 中可用的各种字符串聚合技术取决于 Oracle 版本、数据库中安装了哪些软件包,以及您是否可以创建新过程来支持这一点,或者是否希望在纯 SQL 中完成它。
如果您使用的是 11.2,最简单的选择是使用内置的 LISTAGG 分析函数。
如果您使用的是早期版本,我的首选是使用自定义聚合函数(Tim 的 string_agg)。
Tim Hall has a page that covers the various string aggregation techniques available in Oracle depending on the Oracle version, what packages are installed in the database, and whether you can create new procedures to support this or whether you want it done in pure SQL.
If you are using 11.2, the simplest option would be to use the built-in LISTAGG analytic funciton
If you are using an earlier version, my preference would be to use the custom aggregate function (Tim's string_agg).