Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formating a phone number string in MySQL

I was wondering if there is a simpler way in MySQL to take a 10 digit phone number 9876543210 and display it in the format (987) 654-3210. I have code that works fine but I was wondering if there was another way perhaps similar to DATE_FORMAT().

The code I'm using:

IF(phone_cell != '',
    CONCAT('(',
            SUBSTRING(phone_cell, 1, 3),
            ') ',
            SUBSTRING(phone_cell, 4, 3),
            '-',
            SUBSTRING(phone_cell, 7, 4)),
    '') AS Mobile

The part I'm seeking is to replace the CONCAT statement.

like image 876
cupojava1 Avatar asked Sep 03 '25 06:09

cupojava1


1 Answers

No. Unfortunately, there is no such method as to format the phone number in MySQL. Your concat method is working fine.

like image 177
stackFan Avatar answered Sep 04 '25 18:09

stackFan