我正在尝试使用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
答案 0 :(得分:0)
这是我的意思是-如果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
中将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
答案 1 :(得分:0)
这是我到目前为止所期望的
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