如何连接字符串?
我使用的是 Oracle 10g,表结构如下: ID, 我想按 id分组
并连接段落。每个段落可能有 1500 个字符或更多。
当我尝试 wm_concat 函数时,它抱怨字符串缓冲区太小。我实际上尝试了 Oracle 网站上的许多示例,但它们都失败了,并出现字符串缓冲区太小的错误。
select id, wm_concat(paragraph) from paragraphs group by id
我该如何解决这个问题?
I'm on Oracle 10g and have the following table structure:
id,
paragraph
I want to group by id and concatenate the paragraphs. Each paragraph maybe 1500 characters or more.
When I try the wm_concat function, it complains that the string buffer is too small. I actually tried many of the examples on Oracle's website and they all fail with the error the string buffer is too small.
select id, wm_concat(paragraph) from paragraphs group by id
how do I solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以,我猜测错误是
ORA-06502
我可以理解您可能会认为这在这种情况下不适用于您。然而,这是
wm_concat
的错。这是一个函数,并受到 Oracle PL\SQL 中最大 varchar 长度的限制,即 32,767 和标准 SQL 中的 4,000。不幸的是,我认为,由于 wm_concat 的工作方式或由于函数内的任何较低约束,或者因为您在选择中使用它,您无法接近上限。还有另一个选项,
stragg
,Tom Kyte 的字符串聚合函数。如果我们看一下两者之间的以下比较,您会发现它们的执行几乎相同,并且两者的限制都是大约 4,000 的长度,即标准 SQL 最大值。stragg
稍微快一些,可能是由于缓存的原因。至于解决,恐怕解决不了。一旦你达到了这个极限,就这样了。您必须找到一种不同的聚合方式,或者问问自己是否真的需要这样做。
So, I'm guessing the error is
ORA-06502
and I can see how you might think that this doesn't apply to you in this situation.However, this is the fault of
wm_concat
. This is a function and is constrained by Oracle's maximum varchar length in PL\SQL of 32,767 and 4,000 in standard SQL. Unfortunately, I assume, because of the way that wm_concat works or because of any lower constraints within the function or because you're using it in a select you can't get anywhere near the upper limit.There is another option,
stragg
, Tom Kyte's string aggregate function. If we look at the following comparison between the two you'll see that they perform almost identically and that the limit of both is a length of around 4,000, i.e. the standard SQL maximum.stragg
is slightly faster, probably due to caching.As for solving it, I'm afraid you can't. Once you hit that limit that's it. You'll have to find a different way of doing your aggregations or ask yourself if you really need to.