Skip to content
Advertisement

Oracle developer. ORA-01722 Invalid Number when using UNION

I have this problem:

I have two tables: Table A and Table B, with the same column called PK_COLUMN that in both tables are numeric(8, 0).

I want to make this union:

And I got the next error code:

ORA-01722 Invalid number.

The problem is that when I execute the both parts of the union separately they work perfectly!

Advertisement

Answer

As Dominik Klug stated, one of the values in pk_column can not be converted to an INT. You are not getting an error when running the queries individually because you are not scanning all of the rows, just a subset of what is returned first. If you run queries like

you will be able to identify which table has problematic records.

If you are on Oracle 12.2 or higher, you can use the VALIDATE_CONVERSION function to identify which values are failing to convert to an INT with queries like the ones below.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement