Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check if a string contains a number

Tags:

sql

oracle

I need to check if a string contains a number. Any number. Not wether or not the string IS a number, but if it contains one.

Examples:

'test' = no numbers.

'test2' = contains number.

like image 853
Nicolai Avatar asked Jul 05 '12 09:07

Nicolai


1 Answers

Using a regular expression:

SELECT *
FROM test
WHERE REGEXP_LIKE(testcol, '[[:digit:]]');

Not using regular expressions:

SELECT *
FROM test
WHERE testcol LIKE '%0%'
    OR testcol LIKE '%1%'
    OR testcol LIKE '%2%'
    OR testcol LIKE '%3%'
    OR testcol LIKE '%4%'
    OR testcol LIKE '%5%'
    OR testcol LIKE '%6%'
    OR testcol LIKE '%7%'
    OR testcol LIKE '%8%'
    OR testcol LIKE '%9%'
like image 185
Álvaro González Avatar answered Sep 21 '22 02:09

Álvaro González