Adsense Ad

Friday 19 May 2017

Oracle: ORA-01790 Error Message

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 function, TO_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.

No comments: