Solved

clean up the table.

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

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.

Question has a verified solution.

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

Suggested Solutions

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

813 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

9 Experts available now in Live!

Get 1:1 Help Now