Search code examples
sqloracle-databasestring-aggregation

getting error while aggregating a huge string with xmlagg


I am trying to aggregate a String using xmlagg but i am facing error. here is the 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

When i run this i found below error

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


Solution

  • This is what i was expecting so far

    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