使用XMLAGG函数组合多个值并最终在结果上应用PIVOT时,出现错误“数据类型不一致:预期的%s得到了%s”。
我尝试删除PIVOT部分中的聚合函数(MAX,MIN等),当我删除PIVOT时,查询没有问题。 PIVOT是否不适用于XMLAGG列?
SELECT *
FROM
(SELECT pr.id PR_ID,
p.name PROJECT,
df.name field,
(SELECT (XMLAGG(XMLELEMENT (e, SUBSTR(s_value, - instr(reverse(s_value), '\') + 1)
|| '<eof>')).EXTRACT('//text()').GetClobVal())
FROM pr_addtl_data pad2
WHERE pad2.pr_id = pr.id
AND pad2.data_field_id=df.id
) "Files"
FROM pr pr
LEFT OUTER JOIN pr_addtl_data pad
ON pr.id=pad.pr_id
LEFT OUTER JOIN project p
ON pr.project_id = p.id
LEFT OUTER JOIN data_fields df
ON pad.data_field_id=df.id
WHERE df.name IN ('Attached Files','Certificate of Audit Files')
AND p.name LIKE 'Audit'
AND pr.is_closed = 1
GROUP BY pr.id,
p.name,
df.id,
df.name
) PIVOT ( MAX("Files") FOR field IN ('Attached Files','Certificate of Audit Files') )