11

Possible Duplicate:
How can I use mySQL replace() to replace strings in multiple records?
MySQL search to ignore hyphens

What is the best way to remove hyphens from a field using mysql UPDATE without php?

field: 211-555-1212 > 2115551212
Community
  • 1
  • 1
chrisrth
  • 1,182
  • 3
  • 15
  • 36
  • 4
    Google `mysql replace string`, 1st result – Pekka Oct 23 '12 at 16:09
  • 2
    Very similar to http://stackoverflow.com/questions/4271186/how-can-i-use-mysql-replace-to-replace-strings-in-multiple-records - May have your answer. – Chalise Oct 23 '12 at 16:10

1 Answers1

43

You can use the REPLACE() function, for UPDATE

UPDATE yourtable
SET field = replace(field, '-', '')

See SQL Fiddle With Demo

For SELECT:

SELECT replace(field, '-', '') field
FROM yourtable
Taryn
  • 242,637
  • 56
  • 362
  • 405