我正在使用SYS_CONNECT_BY_PATH做字符串聚合。查询的一般形状是这样的:SYS_CONNECT_BY_PATH导致“ORA-01489:字符串连接的结果太长”
select /*a bunch of fields unrelated to the problem*/,
--Use SYS_CONNECT_BY_PATH to glue together all the chunks of XML.
--The XSL header and footer are prepended and appended here.
, XMLType(to_clob('<?xml version="1.0"?><!-- begining of XSL file -->,'<!-- Next Section -->'))||'</xsl:stylesheet>')) AS XSL
from (
select /*a bunch of fields unrelated to the problem*/
case when x = 1 then to_clob('
/*a bunch of XSL*/
<xsl:text>'||subq.new_c_value||'</xsl:text>
/*a whole bunch more xsl*/')
else
to_clob('/*a bunch of different XSL*/
<xsl:text>'||subq.new_f_value||'</xsl:text>
/*a whole bunch more xsl*/')
end as xsl,
--curr and prev are to help with using sys_connect_by_path do string aggregation.
rownum AS curr,
rownum -1 AS prev
from (Select /* details of subq not relevant */) as subq
)
CONNECT BY prev = PRIOR curr
START WITH curr = 1;
基本上,我正在运行一个查询来生成用于纠正XML文件的XSL。我使用sys_connect_by_path将字符串合并为一个单独的块,这比复制和粘贴许多行中的许多值更简单。我无法使用任何自定义字符串聚合函数,因为此查询在生产数据库上运行,我无法按照自己的意愿创建函数。
的问题是,运行我的查询将返回:
ORA-01489: result of string concatenation is too long 01489. 00000 - "result of string concatenation is too long" *Cause: String concatenation result is more than the maximum size. *Action: Make sure that the result is less than the maximum size.
...在那里有太多的数据情况。正如你所看到的,我一直在将to_clob()
函数应用到我认为可能有所帮助的任何地方,但它似乎没有太大的区别。除了使用PL/SQL之外,还有其他方法可以处理吗?我宁愿将它保留为查询,因为此查询的结果会导出到报表模板,该模板会与XSL并排显示大量有用的信息。能够在一个步骤中完成所有这些将是很好的,而不是通过几个步骤。
(Oracle 10g中)
最终,我找到了这个网页:
http://www.sqlsnippets.com/en/topic-11787.html
关于甲骨文字符串聚合技术。我怀疑唯一能在我的情况下工作的是XML方法和Model方法。我无法让模型方法正常工作,所以我只是使用XML方法。
这将会很艰难。 [这是关于主题的有趣的论坛帖子](https://forums.oracle.com/forums/thread.jspa?threadID=963324)。引用一个答案:“*您可以使用SYS_CONNECT_BY_PATH在子查询中形成部分字符串,然后将这些部分连接到主查询中的CLOB *。祝你好运! –