Search phone numbers in database ignoring special characters

后端 未结 4 1669
你的背包
你的背包 2021-01-14 02:37

I have a database table of customers where customer\'s phone numbers are stored in a field named phoneNumber.

customerId | customerName | phoneNumber
1               


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-14 03:14

    You can use the REGEXP operator (or it's synonym RLIKE) in a WHILE clause. For the regular expression, put in [^0-9]* between each digit of the number you want to find. For instance:

    SELECT * FROM customers WHERE
      phoneNumber RLIKE
      '[^0-9]*0[^0-9]*2[^0-9]*1[^0-9]*3[^0-9]*3[^0-9]*8[^0-9]*3[^0-9]*0[^0-9]*3[^0-9]*0[^0-9]*'
    

    It's awful, but it should work.

提交回复
热议问题