我正在尝试使用listagg函数,如下所示,但是得到了ORA-01489:字符串连接的结果太长了。
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表中有一些LocationID,它们有超过20个条目(最大值为254),对于这些行,我希望连接的字符串超过最多4000个字符。但是,如果count(sequencenumber)= 20,则连接的字符串长度将小于500.即使对于我使用HAVING子句排除的位置,Oracle是否会执行连接,并报告错误?
我已尝试从Oracle Sql Developer和SQL Plus运行查询。
如果有人能对这个问题有所了解,我将不胜感激。
由于
答案 0 :(得分:2)
您需要先减少聚合的行数(如您所猜测的那样),然后对减少的数字应用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;
答案 1 :(得分:1)
Oracle是否对我使用HAVING子句排除的位置执行连接,并报告错误?
是