[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Simple sql question

Posted on 2002-07-11
6
Medium Priority
?
289 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
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 explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

650 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