GeekInterview.com
Series: Subject: Topic:
Question: 15 of 213

Get Numeric Values only using SQL ?

I have table with one column. type varchar.. PHONE --------------- 99samn44423m44 8034skdf3453a2 909090abc4567d i want to get numeric values.. i mean my output will be PHONE --------------- 994442344 80343453a2 9090904567 thanks in advance.. Sateesh
Asked by: sateesh44 | Member Since Oct-2010 | Asked on: Nov 24th, 2011

View all questions by sateesh44   View all answers by sateesh44

Showing Answers 1 - 7 of 7 Answers
Varsha

Answered On : Dec 8th, 2011

This can be done by using the TRANSLATE function as it replaces character by character.

Yes  1 User has rated as useful.
  
Login to rate this answer.
Swathy

Answered On : Dec 12th, 2011

Varsha could you please write the query for this above question?

  
Login to rate this answer.
kirathakudu

Answered On : Dec 13th, 2011

View all answers by kirathakudu

translate(PHONE,[a,b,c,d,e,f..etc],SPACE)

where ever there is an alphabet it will be replaced by space

eg:

PHONE = 32663cdefh3456
after translate PHONE = 32663 3456

translate( string1, string_to_replace, replacement_string )

  
Login to rate this answer.
sanjay

Answered On : Jan 5th, 2012

Code
  1. SELECT REPLACE(TRANSLATE(909090abc4567d,a,b,c,d,e,f,g, ), ,) FROM dual

Yes  1 User has rated as useful.
  
Login to rate this answer.
sriram

Answered On : Feb 24th, 2012

Code
  1. SELECT columnname FROM tablename WHERE regexp_like(columnname,^[[:digit:]]+$) ;

  
Login to rate this answer.
naga

Answered On : Mar 12th, 2012

Code
  1. SELECT REPLACE(TRANSLATE(LOWER(99sAmn44423mz44),abcdefghijklmnopqrstuvwxyz, ), ,) FROM dual

  
Login to rate this answer.
Abhishek

Answered On : Aug 23rd, 2012

Code
  1. declare  @temp_numeric TABLE (value nvarchar(500))
  2. declare @i int=1,@len int,@ans nvarchar(100)=,@str nvarchar(100)
  3. DECLARE @count INT
  4.  
  5. SELECT VALUE INTO #temp FROM dbo.numeric
  6.  
  7. SELECT * FROM #temp
  8.  
  9. SET @count=(SELECT COUNT(*) FROM dbo.#temp)
  10. WHILE(@count>0)
  11. BEGIN
  12.  
  13.  
  14. SET @str = (SELECT TOP (1) value FROM #temp)
  15.  
  16. SET @len=(SELECT LEN(@str))
  17.  
  18. while(@i<=@len)
  19.  BEGIN
  20.      
  21.   IF(isnumeric(SUBSTRING(@str,@i,1))=1)
  22.   begin
  23.   SET @ans=@ans+(SELECT SUBSTRING(@str,@i,1))
  24.   end
  25.   SET @i=@i+1
  26.  
  27.  END --inner loop ends
  28.  
  29. DELETE TOP(1) FROM #temp
  30. SET @count=(SELECT COUNT(*) FROM #temp)
  31.  
  32.  INSERT INTO @temp_numeric VALUES(@ans)
  33.  
  34.  SET @i=1
  35.  SET @ans=
  36. END --outer while loop
  37.  
  38.  
  39.  SELECT * FROM @temp_numeric
  40.  
  41.  DROP TABLE #temp

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Ads

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.