Solved

clean up the table.

Posted on 2008-06-19
4
952 Views
Last Modified: 2013-12-07
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. ?
0
Comment
Question by:vishali_vishu
  • 2
4 Comments
 
LVL 29

Accepted Solution

by:
MikeOM_DBA earned 500 total points
Comment Utility

DELETE FROM MyTable

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

Open in new window

0
 
LVL 14

Expert Comment

by:ajexpert
Comment Utility
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
 
LVL 7

Expert Comment

by:Cedric_D
Comment Utility
I propose the simpler way:

DELETE FROM MyTable WHERE ISNUMERIC(field) = 0

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

Expert Comment

by:MikeOM_DBA
Comment Utility

ISNUMERIC() is not an Oracle function.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to recover a database from a user managed backup

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now