Need help writing a search query

My database contains a list of phone numbers like varchar. The phone number can be in any of these formats.

12323232323 1-232-323 2323 232-323-2323 2323232323 

Instead of a symbol can be ( ) . or space And if I'm looking for 12323232323, 1-232-323 2323, 232-323-2323 or 2323232323, it should display all these results. I need to write a query for this.

+6
source share
3 answers

I think that this is not effective in real time, I offer two options.

  • clear data, so there will be only one format.

  • add another column that contains pure data, so when you search, you look for this column, when displayed, you can display various format data.

+10
source

I agree with James, but if you really need to search the database as it is, perhaps the MySQL REPLACE statement will take you where you need to go. Sort of

 select * from mytable where replace(crazynumber,'-','')='23232323'; 
+2
source

How to replace multiple characters in SQL?

Can MySQL replace multiple characters?

Agree with James, but if you really need to do this, these two links suggested prefect solutions for your scenario.

+1
source

Source: https://habr.com/ru/post/901087/


All Articles