DB2逗号分隔输出 [英] DB2 comma separated output
问题描述
如何在DB2中获取sql
中的逗号分隔列值的内置函数,例如,如果有列具有此策略ID的列,并且具有相同ID的3行,但在三行中有三个不同的角色,则它应该检索一行中的行3,4,5
例如
code> 1。 45552
2. 45553
3. 45554
输出 4555 2,3,4
在一行中的DB2
这正是您需要的:
http://radheshk.blogspot.com/2008/02/sql-tips-techniques-string-aggregation.html
遗憾的是,没有办法容易地(或不知道)在DB2中定义一个自定义聚合函数。所以一个人必须诉诸递归查询,如上面的例子。
解决这个问题的另一个方法是使用光标,但这可能更糟糕了。 >
How to get inbuilt function for comma separated column values in sql in DB2 , e.g if there are columns with this policy id and it has 3 rows with the same id but have three different roles in three rows , then it should retrieve the rows in one row "3,4,5"
e.g.
1. 4555 "2"
2. 4555 "3"
3. 4555 "4"
output 4555 2,3,4
in a DB2 in one row
This is exactly what you need:
http://radheshk.blogspot.com/2008/02/sql-tips-techniques-string-aggregation.html
Sadly, there is no way to define a custom aggregate function in DB2 easily (or not that I know of). So one must resort to recursive queries, as in the example above.
Another way to solve this problem involves cursors, but that is probably even worse...
这篇关于DB2逗号分隔输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!