简体   繁体   中英

SQL Select CASE-WHEN - How to remove formatting from telephone numbers

I have a SQL Select statement that creates a table from a number of fields. I'm using the CASE/WHEN to change some of the values but I'm stuck on how to format the results.

SELECT DISTINCT field1, field2, field3, field4,
CASE meta_value WHEN 'male' then 'M' WHEN 'female' THEN 'F' etc.

The telephone numbers that are returned may have other characters that I would like to remove, ie:

(404) 202-2039
404-202-2039
1-404-202-2039

I would like to return only the numbers with no spaces or other characters, hyphens, parentheses, etc:

4042022039

Any ideas on how to best accomplish this?

如果您运行的是 MySQL 8.0,则可以使用regexp_replace()

regexp_replace(phone_number, '[^0-9]', '') clean_phone_number

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM