?
Solved

Simple sql question

Posted on 2002-07-11
6
Medium Priority
?
288 Views
Last Modified: 2012-06-21
Hi
I have a table in which a column is declared to be of type varchar.
Almost all the values for this column are numbers like 100, 120, 140, etc but some of the values are alpha characters like 'hundred', 'one twenty five' etc.

Now I want to delete all these alpha entries from the table.
Is there a simple sql query which can do this ?
thanks
0
Comment
Question by:AInamdar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 2

Expert Comment

by:ddandekar
ID: 7148264
Assuming that the first character in varchar column c1 is numeric for the rows which you want to retain then following will delete the rows with nonnumeric first characters
delete from t1
where  substr(c1,1,1) not in
 ( '0','1','2','3','4','5','6','7','8','9')
/

This will have to be repeated for 2nd character , 3rd character etc.
0
 
LVL 3

Expert Comment

by:mnicoras
ID: 7148483
Hi,

not so sim[ple.

solution 1:

create or replace function is_char( iVal varchar2 ) return number is
mVal number;
mRet NUMBER;
begin
  begin
    mVal := iVal;
    mRet := 1;
  exception
    when others then
      mRet := 0;
  end;
return mRet;
end;

delete from <my_table> where is_char(<my_column>)=0;

solution 2:

delete from <my_table>
where
  instr(lower(<my_column>),'a')+
  instr(lower(<my_column>),'b')+
  instr(lower(<my_column>),'c')+
  instr(lower(<my_column>),'d')+
  instr(lower(<my_column>),'e')+
...
  instr(lower(<my_column>),'z') > 0
;


best regards,
Marius Nicoras
0
 

Expert Comment

by:justvineet
ID: 7148658
The following query will delete all the rows which have an alpha in its value.

delete from t1 where
ascii(substr(c1,1,1)) not between 48 and 57 OR
ascii(substr(c1,2,1)) not between 48 and 57 OR
ascii(substr(c1,3,1)) not between 48 and 57 OR
......
......
ascii(substr(c1,size_of_c1-1,1)) not between 48 and 57 OR
ascii(substr(c1,size_of_c1,1)) not between 48 and 57
/

Regards,
Vineet.
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 3

Accepted Solution

by:
rkogelhe earned 120 total points
ID: 7148755
update mytable
set mynum = null
where
  translate(mynum,'X0123456789','X') is not null;

or

delete mytable
where
  translate(mynum,'X0123456789','X') is not null;
0
 

Author Comment

by:AInamdar
ID: 7149712
Query from rkogelhe  was short and worked for me .
thanks.
0
 
LVL 3

Expert Comment

by:patelgokul
ID: 9392149
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
accept rkogelhe's comment as an answer
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

patelgokul
EE Cleanup Volunteer
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
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.
Suggested Courses

801 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