How to select lines only where the first digit is from 0 to 9?

As far as I know, I can do something like:

"SELECT * 
 FROM my_table 
 WHERE my_field LIKE '0%' 
 OR my_field LIKE '1%' 
 OR my_field LIKE '2%' ";

Is there a way to achieve this using regex or something like this:

"SELECT * 
 FROM my_table 
 WHERE my_field LIKE [only first char is 0-9]"??

EDIT: the field is not numeric, and it could be something like "1 People", "211 Pies", etc.

+5
source share
5 answers

try it

SELECT * 
FROM BadlyDesignedTable 
WHERE AnswerColumn RLIKE '^[0-9]+'

I was wondering if a re-expression is possible in where he found it on Google in 30 seconds.

+7
source
SELECT * FROM table WHERE field REGEXP '^[0-9]' 
+2
source
Select * From my_table Where (REGEXP_LIKE(my_field, '[[:digit:]]%'))

(REGEXP_LIKE(Source_String, '[[:character class:]]')) - , , , . , , .

http://docs.oracle.com/cd/B14117_01/server.101/b10759/conditions018.htm

EDIT: * From my_table (SUBSTR (my_field, 1,1) = '[[: digit:]]') , .

+1
SELECT *
FROM my_table
WHERE left(my_field,1) REGEXP '^[0-9]+';

MSSQL,

SELECT *
FROM my_table
WHERE isNumeric(left(my_field,1)) = 1
0

Simple without regular expressions:

SELECT *, SUBSTR(my_field, 1, 1) AS mf FROM my_table HAVING mf BETWEEN '0' AND '9';

Important quotes in the FROM clause!

0
source

All Articles