Oto Shavadze
Oto Shavadze

Reputation: 42753

Get only digits using regexp

I have in table column pnum_s

I need get only that rows, which value in column pnum_s is exactly 10 symbol and all these symbols are only digits

what query must write for this?

I am trying this:

SELECT * FROM mytable WHERE pnum_s REGEXP '^\d+$'

But this not returns 0 rows.

Upvotes: 11

Views: 55815

Answers (4)

rollcona
rollcona

Reputation: 163

Check out the reference page.

http://dev.mysql.com/doc/refman/5.1/en/regexp.html#operator_regexp

What you're looking for is this:

SELECT * FROM mytable WHERE pnum_s REGEXP '^[[:digit:]]{10}$';

Upvotes: 6

danpaq
danpaq

Reputation: 324

I think with Mysql you'll want something like this:

^[[:digit:]]{10}$

Upvotes: 7

RandomSeed
RandomSeed

Reputation: 29759

The pattern you are looking for is either '^[0-9]{10}$' or '^[[:digit:]]{10}$'.

Everything is in the manual.

Upvotes: 24

Casimir et Hippolyte
Casimir et Hippolyte

Reputation: 89547

try this pattern:

'^[0-9]{10}$'

Upvotes: 2

Related Questions