Sql SYS_CONNECT_BY_路径导致“ORA-01489:字符串连接的结果太长”
我使用SYS\u CONNECT\u BY\u PATH进行字符串聚合。查询的一般形状如下所示:Sql SYS_CONNECT_BY_路径导致“ORA-01489:字符串连接的结果太长”,sql,oracle,Sql,Oracle,我使用SYS\u CONNECT\u BY\u PATH进行字符串聚合。查询的一般形状如下所示: 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
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\u connect\u by\u 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并排显示许多有用的信息。如果能够在一个步骤而不是几个步骤中完成所有这些,那将是一件好事
甲骨文10g
最后,我找到了这个页面:
关于Oracle中的字符串聚合技术。我怀疑在我的情况下唯一有效的方法是XML方法和Model方法。我无法让模型方法正常工作,所以我只使用XML方法。很抱歉,我的答案依赖于创建字符串聚合包,但从长远来看可能有用 您可以使用Stragg包而不是sys\u connect\u by\u path 在下面的链接中提到了AskTom
在这个包中,有一个声明和一些处理long的逻辑,您可以根据需要更改这些声明和逻辑来处理CLOB。引用一个答案:您可以使用SYS_CONNECT_BY_PATH在子查询中形成字符串的一部分,然后在主查询中将这些部分连接到CLOB中。。祝你好运尽管为了报告生产数据,我正在对生产服务器运行此查询,但这可能会起作用。因为它是生产服务器,所以我不能为了方便我的报告而编译新的包。这似乎是可行的,但我现在有两个查询:一个查询报告数据,另一个查询xmlagg的结果。也许没有别的办法。。。
select
xmlroot
(
xmlelement
(
"xsl:stylesheet"
,XMLAttributes
(
'1.0' as version
,'http://www.w3.org/1999/XSL/Transform' as "xmlns:xsl"
,'http://test' as "xmlns:ns0"
)
,(
xmlagg(xmlelement("xsl:text", val))
)
)
,version '1.0'
)
from
(
--Test >4000 characters
select 1 id, cast(rpad('a',4000,'a') as varchar2(4000)) val from dual union all
select 1 id, cast(rpad('b',4000,'b') as varchar2(4000)) val from dual union all
select 1 id, cast(rpad('c',4000,'c') as varchar2(4000)) val from dual union all
select 1 id, cast(rpad('d',4000,'d') as varchar2(4000)) val from dual
);