получить ошибку при агрегировании огромной строки с xmlagg - PullRequest
0 голосов
/ 11 мая 2019

Я пытаюсь агрегировать строку, используя 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

Ответы [ 2 ]

0 голосов
/ 15 мая 2019

Это то, что я ожидал до сих пор

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
0 голосов
/ 13 мая 2019

Это то, что я имел в виду, говоря, что - если тип данных 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  ;

[EDIT]

Применяя TO_NUMBER к DA.GID в CASE, но оставляя его как в строке 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
...