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
  • 40,603
  • 55
  • 152
  • 236

4 Answers4

23

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

Everything is in the manual.

RandomSeed
  • 29,301
  • 6
  • 52
  • 87
7

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

^[[:digit:]]{10}$
Jin Kwon
  • 20,295
  • 14
  • 115
  • 184
danpaq
  • 324
  • 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
  • 20,295
  • 14
  • 115
  • 184
rollcona
  • 163
  • 10
2

try this pattern:

'^[0-9]{10}$'
Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125