14

I need to select just the rows within a sql table which contain no numerical values whatsoever, here's an example table:

AddressLine1
-------------
59 Prospect Road
Rose House
24 St. Pauls Place
1 Oxford Avenue
9 Stonecross Road
65 Wood Common
19 Falcon Close
Thorn House
16 Poplars Close
52 Coombes Road
12 Brinsmead
14 Meadow Close
15 Rowlatt Drive

In this example I would just be looking for "Rose House" and "Thorn House" rows to be returned.

Any suggestion on the code I should be using would be gratefully received.

3
  • You can consider using regular expressions, some examples you will find here on StackOverflow Commented Jan 7, 2016 at 10:33
  • Hi @adam-haycok , ah ... better formatting ... ah ... 2 thumbs up | pat in the back | high 5 Commented Jan 7, 2016 at 10:38
  • Some answers were given but the better option would be to split it up in two columns: AddressNumber and AddressName. Commented Jan 7, 2016 at 10:39

3 Answers 3

32
select * from tab
where AddressLine1 not like '%[0-9]%'

try this

Sign up to request clarification or add additional context in comments.

2 Comments

You are Welcome @Adam
Using this query I am not able to get non numeric values that have an alpha character in the middle of the value
12

I think the actual answer should be:

select * from tab where AddressLine1 like '%[^0-9]%'

According to: https://learn.microsoft.com/en-us/sql/t-sql/language-elements/like-transact-sql?view=sql-server-ver15

1 Comment

This actually was the answer I needed when looking this up, but just a heads up, based on the OP, I think he's looking for values that don't have any number in the text, this one will return values that have numbers in them. So, I think this one is perfect if you're looking for any value that is not a number, but for the OP I think he's looking for a string without any numbers in it.
-1

This is the way:

SELECT * FROM TABLE_NAME WHERE NOT REGEXP_LIKE(COLUMN_NAME, '^-?[0-9.]+$');

This also excludes values which contain decimals.

2 Comments

I think they talk about TSQL not Oracle
This is not mentioned in the original post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.