我拥有3个视图的并集。视图中的数据类型相同,但是出现错误“ ORA-01790:表达式必须具有与相应表达式相同的数据类型”。最后一个联合将Clob转换为varchar以与上述视图匹配。我在下面给出代码。请帮助我解决这个问题
SELECT
ROWNUM rownum_1,
customer_trx_id,
customer_trx_line_id,
item_name,
quantity_invoiced,
unit_selling_price,
extended_amount,
line_number,
row_num,
line_description,
tax_perc,
line_total,
tax_amount,
uom,
po_line FROM
apps.gnet_bpa_inv_lines_cons
WHERE
:p_summary = 'N'
AND
customer_trx_id = 3725097
UNION ALL
SELECT
ROWNUM rownum_1,
customer_trx_id,
customer_trx_line_id,
item_name,
quantity_invoiced,
unit_selling_price,
extended_amount,
line_number,
row_num,
line_description,
tax_perc,
line_total,
tax_amount,
uom,
po_line
FROM
apps.gnet_bpa_inv_lines_cons_summ
WHERE
:p_summary = 'Y'
AND
customer_trx_id = 3725097
UNION ALL
SELECT
MAX(ROWNUM) rownum_1,
customer_trx_id AS customer_trx_id,
MAX(customer_trx_line_id) AS customer_trx_line_id,
dbms_lob.substr(
XMLAGG(xmlelement(e,item_name,',').extract('//text()') ORDER BY
po_line).getclobval(),
4000,
1
) AS item_name,
LISTAGG(quantity_invoiced,',') WITHIN GROUP(ORDER BY po_line) AS
quantity_invoiced,
MAX(unit_selling_price) AS unit_selling_price,
SUM(extended_amount) AS extended_amount,
MAX(line_number) AS line_number,
LISTAGG(row_num,',') WITHIN GROUP(ORDER BY po_line) AS row_num,
dbms_lob.substr(
XMLAGG(xmlelement(e,line_description,',').extract('//text()') ORDER BY
po_line).getclobval(),
4000,
1
) AS line_description,
LISTAGG(tax_perc,',') WITHIN GROUP(ORDER BY po_line) AS tax_perc,
LISTAGG(tax_amount,',') WITHIN GROUP(ORDER BY po_line) AS tax_amount,
SUM(line_total) AS line_total,
LISTAGG(uom,',') WITHIN GROUP(ORDER BY po_line) AS uom,
po_line
FROM
apps.gnet_bpa_inv_lines_cons
WHERE
:p_summary = 'P'
AND
customer_trx_id = 3725097
GROUP BY
po_line,
customer_trx_id
ORDER BY rownum_1;
答案 0 :(得分:2)
LISTAGG(tax_perc,',') WITHIN GROUP(ORDER BY po_line) AS tax_perc,
LISTAGG(tax_amount,',') WITHIN GROUP(ORDER BY po_line) AS tax_amount,
是最后一个联合中的char / varchar数据类型,因为它们在前两个部分中是数字/十进制。检查是否也有其他类似的列,您的问题应该得到解决。