【问题标题】:"ORA-01489:result of string concatenation is too long" (string is small)“ORA-01489:字符串连接的结果太长”(字符串太小)
【发布时间】:2013-04-04 20:58:12
【问题描述】:

我正在尝试按如下方式使用 listagg 函数,但得到 ORA-01489: result of string concatenation is too long.

SELECT LOCATIONID, LISTAGG(TO_CHAR(XPOSITION||','||YPOSITION), ',') WITHIN GROUP (ORDER BY SEQUENCENUMBER) ords
FROM POSITIONPOINTS 
GROUP BY LOCATIONID
HAVING COUNT(SEQUENCENUMBER) = 20;

当我尝试在 Oracle Sql Developer 中运行它时,它会显示前 1550 行,然后报告 ORA-01489 错误。总共应返回 2612 行,所有 ords 值的长度约为 440 个字符。 Sql Developer 返回的行之一的示例是:

22372682 410434.801,551142.885,410434.784,551142.875,410439.801,551141.922,410439.991,551141.795,410439.293,551138.303,410438.531,551137.668,410429.768,551134.302,410427.228,551133.159,410426.212,551132.143,410425.196,551129.667,410421.957,551114.3,410414.972, 551081.28,410413.639,551076.136,410412.94,551073.66,410412.94,551072.326,410413.639,551071.628,410415.798,551070.612,410416.369,551069.469,410416.877,551068.834,410433.23,551061.795

PositionPoints 表中有一些 LocationIDs 有超过 20 个条目(最多 254 个),对于这些行,我希望连接的字符串超过 4000 个字符的最大值。但是,如果 count(sequencenumber) = 20,则连接的字符串长度将小于 500。Oracle 是否即使对我使用 HAVING 子句排除的位置也执行连接,并报告这些错误?

我已尝试从 Oracle Sql Developer 和 SQL Plus 运行查询。

如果有人能阐明这个问题,我们将不胜感激。

谢谢

【问题讨论】:

    标签: sql oracle


    【解决方案1】:

    您需要首先减少要聚合的行数(如您所料),然后将 listagg() 应用于减少的数字。

    类似这样的:

    select locationid, 
           listagg(to_char(xposition||','||yposition), ',') within group (order by sequencenumber) ords
    from (
      select locationid, 
             xposition, 
             yposition, 
             sequencenumber,
             count(sequencenumber) over (partition by locationid) as cnt
      from positionpoints 
    ) t
    where cnt = 20
    group by locationid;
    

    【讨论】:

      【解决方案2】:

      Oracle 是否甚至对我使用 HAVING 子句排除的位置执行连接,并在这些位置上报告错误?

      是的。

      【讨论】:

        猜你喜欢
        • 2017-02-06
        • 2016-05-28
        • 2011-08-13
        • 1970-01-01
        • 2015-06-28
        • 2012-05-12
        • 1970-01-01
        • 2013-01-29
        • 2021-07-04
        相关资源
        最近更新 更多