Solved

clean up the table.

Posted on 2008-06-19
4
955 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
ID: 21824302

DELETE FROM MyTable

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

Open in new window

0
 
LVL 14

Expert Comment

by:ajexpert
ID: 21824368
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
ID: 21824893
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
ID: 21825334

ISNUMERIC() is not an Oracle function.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

912 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

17 Experts available now in Live!

Get 1:1 Help Now