Solved

clean up the table.

Posted on 2008-06-19
4
963 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
join 2 views with 5 conditions 3 61
sort a spool into file output in oracle 1 45
Checking for column width 8 29
Procedure syntax 5 40
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…
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.  …
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

830 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