Search phone numbers in database ignoring special characters

后端 未结 4 1672
你的背包
你的背包 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:11

    You can clean the phoneNumber before comparing it:

    select * from table where replace(replace(replace(replace(phoneNumber,'('), ')'),' '), '-') = '0213383030';
    

    I would, instead, add another column to the table that contains the phoneNumber but without the characters you don't want and then use that column for comparisons.

提交回复
热议问题