Lab-verifiedReproduced and fixed on Oracle AI Database 26ai Free 23.26.3.0.0 · 2026-11-24 · container image gvenzl/oracle-free:23-slim
ORA-01790 appears when the SELECTs in a UNION, UNION ALL, INTERSECT or MINUS have the same number of columns, but a column in the same position has a different data type group: number, character or date. Oracle does not convert them for you here.
The * under the error marks the column in the first SELECT whose type does not match. Compare that position in every SELECT.
01The same column is NUMBER in one table and VARCHAR2 in the other
ITEMS.ITEM_CODE is NUMBER and ITEMS_LEGACY.ITEM_CODE is VARCHAR2, as USER_TAB_COLUMNS shows. The names are the same, but the types are not, so the UNION ALL failed at item_code.
The legacy codes contain letters (A-07), so convert the number side to text: TO_CHAR(item_code). Then both 101 and A-07 were returned.
Setup
CREATE TABLE items (item_code NUMBER, item_name VARCHAR2(20));
CREATE TABLE items_legacy (item_code VARCHAR2(10), item_name VARCHAR2(20));
INSERT INTO items VALUES (101, 'Bolt');
INSERT INTO items_legacy VALUES ('A-07', 'Nut');
COMMIT;Table created.
Table created.
1 row created.
1 row created.
Commit complete.SELECT item_code, item_name FROM items
UNION ALL
SELECT item_code, item_name FROM items_legacy;SELECT item_code, item_name FROM items
*
ERROR at line 1:
ORA-01790: expression must have same datatype as corresponding expression
Help: https://docs.oracle.com/error-help/db/ora-01790/COLUMN table_name FORMAT A14
COLUMN column_name FORMAT A12
COLUMN data_type FORMAT A10
SELECT table_name, column_name, data_type FROM user_tab_columns
WHERE table_name IN ('ITEMS', 'ITEMS_LEGACY') AND column_name = 'ITEM_CODE'
ORDER BY table_name;TABLE_NAME COLUMN_NAME DATA_TYPE
-------------- ------------ ----------
ITEMS ITEM_CODE NUMBER
ITEMS_LEGACY ITEM_CODE VARCHAR2
2 rows selected.Convert toward the type that can hold every value. Text like A-07 cannot become a number, so use TO_CHAR on the NUMBER side.
SELECT TO_CHAR(item_code) AS item_code, item_name FROM items
UNION ALL
SELECT item_code, item_name FROM items_legacy;ITEM_CODE ITEM_NAME
---------------------------------------- --------------------
101 Bolt
A-07 Nut
2 rows selected.02Columns are in a different order (SELECT *)
EMP is (EMP_ID NUMBER, NAME VARCHAR2) but CONTRACTORS is (NAME VARCHAR2, CONTRACTOR_ID NUMBER). With SELECT *, the first column is a number on one side and text on the other.
UNION matches columns by position, not by name. Listing the columns in the same order (contractor_id, name) returned 1 KIM and 9001 LEE.
Setup
CREATE TABLE emp (emp_id NUMBER, name VARCHAR2(20));
CREATE TABLE contractors (name VARCHAR2(20), contractor_id NUMBER);
INSERT INTO emp VALUES (1, 'KIM');
INSERT INTO contractors VALUES ('LEE', 9001);
COMMIT;Table created.
Table created.
1 row created.
1 row created.
Commit complete.SELECT * FROM emp
UNION ALL
SELECT * FROM contractors;SELECT * FROM emp
*
ERROR at line 1:
ORA-01790: expression must have same datatype as corresponding expression
Help: https://docs.oracle.com/error-help/db/ora-01790/COLUMN table_name FORMAT A12
COLUMN column_name FORMAT A14
COLUMN data_type FORMAT A10
SELECT table_name, column_id, column_name, data_type FROM user_tab_columns
WHERE table_name IN ('EMP', 'CONTRACTORS')
ORDER BY table_name, column_id;TABLE_NAME COLUMN_ID COLUMN_NAME DATA_TYPE
------------ ---------- -------------- ----------
CONTRACTORS 1 NAME VARCHAR2
CONTRACTORS 2 CONTRACTOR_ID NUMBER
EMP 1 EMP_ID NUMBER
EMP 2 NAME VARCHAR2
4 rows selected.Write the column list in both SELECTs instead of SELECT *.
SELECT emp_id, name FROM emp
UNION ALL
SELECT contractor_id, name FROM contractors; EMP_ID NAME
---------- ------------------------------
1 KIM
9001 LEE
2 rows selected.03A text value such as 'N/A' in a DATE column position
EMP.HIRE_DATE is a DATE, and the applicants part put the string 'N/A' in the same position. DATE and text do not mix in a UNION.
If an empty value is enough, NULL works: CHOI came back with an empty HIRE_DATE. To show N/A, convert the date to text with TO_CHAR(hire_date, 'YYYY-MM-DD'): KIM showed 2024-03-02 and CHOI showed N/A.
Setup
CREATE TABLE emp (emp_id NUMBER, name VARCHAR2(20), hire_date DATE);
CREATE TABLE applicants (app_id NUMBER, name VARCHAR2(20));
INSERT INTO emp VALUES (1, 'KIM', DATE '2024-03-02');
INSERT INTO applicants VALUES (50, 'CHOI');
COMMIT;Table created.
Table created.
1 row created.
1 row created.
Commit complete.SELECT name, hire_date FROM emp
UNION ALL
SELECT name, 'N/A' FROM applicants;SELECT name, hire_date FROM emp
*
ERROR at line 1:
ORA-01790: expression must have same datatype as corresponding expression
Help: https://docs.oracle.com/error-help/db/ora-01790/ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD';
SELECT name, hire_date FROM emp
UNION ALL
SELECT name, NULL FROM applicants;Session altered.
NAME HIRE_DATE
------------------------------ ----------
KIM 2024-03-02
CHOI
2 rows selected.After TO_CHAR, the column is text, so sorting by it sorts as text. The YYYY-MM-DD format keeps the order correct.
SELECT name, TO_CHAR(hire_date, 'YYYY-MM-DD') AS hire_date FROM emp
UNION ALL
SELECT name, 'N/A' FROM applicants;NAME HIRE_DATE
------------------------------ ----------
KIM 2024-03-02
CHOI N/A
2 rows selected.FAQ
What is the difference between ORA-01790 and ORA-01789?
ORA-01789 means the SELECTs return a different number of columns. ORA-01790 means the number is the same but a column in the same position has a different type.
How do I find which column causes ORA-01790?
Look at the * in the error output. It points to the column in the first SELECT. Compare that position in the other SELECTs, or check the types in USER_TAB_COLUMNS.
Can I put NULL in a UNION column instead of a value?
Yes. In the test, NULL in the DATE position worked. Only a non-NULL value of a different type, like 'N/A', caused the error.
The column names are the same, why do I get ORA-01790?
UNION does not look at names. It matches by position and checks the data type. In the test, both tables had ITEM_CODE, but one was NUMBER and the other VARCHAR2.
How we verify
Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.
lab_a and lab_b are ordinary users created for the test; system is the DBA account. Oracle AI Database 26ai Free Release 23.26.3.0.0 - Develop, Learn, and Run for Free 23.26.3.0.0