Reputation: 41
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.
Upvotes: 4
Views: 1537
Reputation: 175716
You could use INSERT
:
SELECT INSERT(INSERT(INSERT(s.num,1,0, '('), 5,0,') '),10,0,'-')
FROM (SELECT '9876543210' AS num) s;
Upvotes: 0
Reputation: 1608
No. Unfortunately, there is no such method as to format the phone number in MySQL.
Your concat
method is working fine.
Upvotes: 3