Link to home
Start Free TrialLog in
Avatar of vishali_vishu
vishali_vishu

asked on

clean up the table.

The table is populated the data and one of the field is Varchar and it represents some integer values.

so with in the sql query i need to compare the field value with an integer.

but unfortunately the data is bit currepted and the field has some #### in it and the sql is working fine if i delete those rows.

The other table has the same problem but it has hundrends of such rows.

how to delete the rows - whose column value is not capable of casting it to integer. ?
ASKER CERTIFIED SOLUTION
Avatar of MikeOM_DBA
MikeOM_DBA
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here could be the logic for deleting corrupted records.

Handle exception where you find that casting is errorring out.
Be sure to note down the exception number.
for e.g. the exception number is ORA-01700
here is pseudo code
BEGIN
SELECT * FROM table1
where col1 = CAST(col2 as integer)
EXCEPTION
WHEN OTHERS THEN
  IF SQLCODE=-1700 THEN
    DELETE FROM table1 WHERE primarykeycol = valueofprimarykey
 END IF;
END;
Avatar of Cedric_D
Cedric_D

I propose the simpler way:

DELETE FROM MyTable WHERE ISNUMERIC(field) = 0

But be aware, it will also delete empty values and nulls.

ISNUMERIC() is not an Oracle function.