使用 xmlagg 聚合一个巨大的字符串时出错

getting error while aggregating a huge string with xmlagg

我正在尝试使用 xmlagg 聚合字符串,但我遇到了错误。这是 xmlagg

select  
            apex_string.format(t1.col_heading, null, null, 1, 2, null)  
          || rtrim(xmlagg(XMLELEMENT(e,apex_string.format(t2.col_heading, null, null, da.n_service, case da.gid when 15 then 3 else 1 end, coalesce(da.service_type, 'Grand Total')),'').EXTRACT('//text()') order by da.c ).GetClobVal(),',')
        , min(da.gid)  
      from  
          data_aggs da  
            cross join std_template t1  
            cross join std_template t2  
      where  
          da.balance_type is null  
      and da.gid in (11, 15)  
      group by  
          t1.col_heading

当我 运行 我发现下面的错误

[Error] Execution (132: 14): ORA-01790: expression must have same datatype as corresponding expression

这就是我所说的意思 - 如果 DA.GID 的数据类型是 VAR(CHAR)2 - 你应该将它与字符串进行比较,而不是数字。注意第 4、5 和 14 行。

SQL> select     apex_string.format(t1.col_heading, null, null, 1, 2, null)
  2               || rtrim(xmlagg(xmlelement
  3                    (e, apex_string.format(t2.col_heading, null, null, da.n_service,
  4                          case da.gid when '15' then '3'       --> here
  5                                      else '1'                 --> here
  6                          end,
  7                          coalesce(da.service_type, 'Grand Total')), '').extract('//text()')
  8                          order by da.c ).getclobval(), ','),
  9             min(da.gid)
 10  from       data_aggs da
 11  cross join std_template t1
 12  cross join std_template t2
 13  where      da.balance_type is null
 14  and        da.gid in ( '11', '15')                            --> here
 15  group by   t1.col_heading
 16  ;

[编辑]

TO_NUMBER 应用到 CASE 中的 DA.GID,但在第 14 行保持原样

  4                          case to_number(da.gid) when 15 then 3       --> here
  5                                      else 1                          --> here
  6                          end,

 14  and        da.gid in ('11', '15')                                   --> here

这是我目前所期待的

select  
          xmlconcat(  
              xmlparse(content apex_string.format(t1.col_heading, null, null, 1, 2, null))  
            , xmlagg(xmlparse(content apex_string.format(t2.col_heading, null, null, da.n_service, case da.gid when 15 then 3 else 1 end, coalesce(da.service_type, 'Grand Total'))) order by da.c))  
        , min(da.gid)  
      from  
          data_aggs da  
            cross join std_template t1  
            cross join std_template t2  
      where  
          da.balance_type is null  
      and da.gid in (11, 15)  
      group by  
          t1.col_heading