Oracle数据库--union all 出现ORA-01790 错误信息

Oracle / PLSQL: ORA-01790 Error Message

Learn the cause and how to resolve the ORA-01790 error message in Oracle.

Description

When you encounter an ORA-01790 error, the following error message will appear:

  • ORA-01790: expression must have same datatype as corresponding expression

Cause

You tried to execute a SELECT statement (probably a UNION query or a UNION ALL query), and all of the queries did not contain matching data types in the result columns.

Resolution

The option(s) to resolve this Oracle error are:

Option #1

Re-write the SELECT statement so that each matching column is the same data type.

For example, if you tried to execute the following UNION query:

SELECT supplier_name
FROM orders
UNION
SELECT quantity
FROM orders_audit;

You would receive an error message as follows:

Oracle PLSQL

Since the supplier_name column is defined as a varchar2 and the quantity column is defined as a number, these columns can not be matching columns.

You can try correcting this UNION query by using a conversion function (ie: TO_CHAR functionTO_NUMBER function, or TO_DATE function) to convert the values to matching data types.

For example:

SELECT supplier_name
FROM orders
UNION
SELECT TO_CHAR(quantity)
FROM orders_audit;

In this example, we've used the TO_CHAR function to convert the quantity column to a data type that is compatible with the supplier_name column.

 

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值