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. ?
LVL 1
vishali_vishuAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
MikeOM_DBAConnect With a Mentor Commented:

DELETE FROM MyTable
 WHERE REPLACE(TRASLATE(TheColumn,'~0123456789','~'),'~','') IS NOT NULL

Open in new window

0
 
ajexpertCommented:
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;
0
 
Cedric_DCommented:
I propose the simpler way:

DELETE FROM MyTable WHERE ISNUMERIC(field) = 0

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

ISNUMERIC() is not an Oracle function.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.