Report Builder 2.0 或 Oracle 字符串聚合
在 Report Builder 2.0 中,我尝试创建一个包含如下数据的表:
Person | StrID's
-------------------
Jim | a, b, c, d
Mary | h, k
Sue | l, m, p, z
问题是我的 Oracle SQL 查询返回以下格式的数据:
Person | StrID
--------------
Jim | a
Jim | b
Jim | c
Jim | d
Mary | h
等等。我无权在 Oracle 中使用 LISTAGG
,如 本教程,我也不能使用 EXPLAIN PLAN
或告诉您我正在使用哪个版本的 Oracle,因为我必须通过非常有限的接口访问数据库。我研究了报表生成器的函数,例如Aggregate
,但找不到将多个字符串值与聚合函数连接在一起的方法。如果我创建一个按人员分组的表,我会为每个 StrID 获得单独的行。使用 Join(Fields!StrID.Value, ", ")
会导致“#Error”显示在表格单元格中,我认为是因为 Fields!StrID.Value
不是实际上是一个多值字段,它是每个人的单个值。
谁能告诉我一种通过 SQL 或 Report Builder 2.0/Visual Basic 在一行中按人员显示关联 StrID 列表的方法?
编辑:我可以使用LAG函数< /a> 如果有人能想出一个创造性的解决方案来使用它。事实证明,我也可以将 PARTITION BY 与 LAG 函数结合使用。
In Report Builder 2.0, I'm trying to create a table with data like the following:
Person | StrID's
-------------------
Jim | a, b, c, d
Mary | h, k
Sue | l, m, p, z
The problem is that my Oracle SQL query returns data in the following format:
Person | StrID
--------------
Jim | a
Jim | b
Jim | c
Jim | d
Mary | h
And so on. I don't have access in Oracle to use LISTAGG
as described in this tutorial, nor can I use EXPLAIN PLAN
or tell you which version of Oracle I'm using because I have to access the database through a very limited interface. I've looked into Report Builder's functions like Aggregate
but cannot find a way to concatenate multiple string values together with an aggregate function. If I create a table grouping by Person, I get separate rows for each of the StrID's. Using Join(Fields!StrID.Value, ", ")
causes "#Error" to show up in the table cell, I assume because Fields!StrID.Value
is not actually a multi-value field, it's a single value per Person.
Can anyone tell me a way of showing a list of the associated StrID's by Person in one row, either through SQL or Report Builder 2.0/Visual Basic?
Edit: I can use the LAG function if anyone can think of a creative solution using that. Turns out I can use PARTITION BY
in conjunction with the LAG
function, too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这里 http://www.sqlsnippets.com/en/topic-11787.html
它们至少有 10 个方法,其中一些不需要创建额外的对象。
您可以尝试其中任何一个,看看它们是否适合您的 Oracle 版本。
Here http://www.sqlsnippets.com/en/topic-11787.html
they have at least 10 methods, some of which do not require creating additional objects.
You may try any of those to see if they suit your Oracle version.
我浏览过 Tom Kyte 网站?如果您搜索“pivot”,结果可能会有所帮助。
例如
http://asktom。 oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:124812348063
或
http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID :15151874723724
不幸的是,我无法访问报告 2.0(幸运的是(?)我从 6i 开始!),所以我无法确认这是否适用于您的环境。
I have had a look on Tom Kyte's site? If you search for "pivot" the results might be of some help.
e.g.
http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:124812348063
or
http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:15151874723724
Unfortunately I don't have access to reports 2.0 (Fortunately(?) I started with 6i!) so I can't confirm that this will work in your environment.
在发现
LAG
函数起作用后,我想我也许能够获得一个StrID
和上一行的StrID
,将它们连接在一起,然后以某种方式继续对Person
的所有行执行此操作。我发现 这个 AskTom 问题 并能够调整它以与我的表格一起使用:我现在以我期望的格式获取数据,即:
After finding out that the
LAG
function worked, I thought I might be able to get aStrID
and the previous row'sStrID
, concatenate them together, and then somehow keep doing that for all the rows for aPerson
. I found this AskTom question and was able to adapt it to work with my tables:I now get data in the format I expected, namely: