11

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

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

But this not returns 0 rows

Oto Shavadze
  • 37,634
  • 51
  • 140
  • 215

4 Answers4

23

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

Everything is in the manual.

RandomSeed
  • 28,589
  • 6
  • 48
  • 86
6

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

^[[:digit:]]{10}$
Jin Kwon
  • 18,308
  • 12
  • 99
  • 160
danpaq
  • 314
  • 1
  • 5
6

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}$';
Jin Kwon
  • 18,308
  • 12
  • 99
  • 160
rollcona
  • 163
  • 10
2

try this pattern:

'^[0-9]{10}$'
Casimir et Hippolyte
  • 85,718
  • 5
  • 90
  • 121