Solved

Simple sql question

Posted on 2002-07-11
6
286 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 3

Accepted Solution

by:
rkogelhe earned 30 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DB migration from Mssql to 12c oracle , data not loading. 3 52
oracle DR - data guard failover. 18 73
Need help on decision table structure 7 58
scheduler notification 9 77
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ā€¦
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
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 configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

732 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