Mysql Phone Number Format

Mysql Phone Number Format is useful when you want to return the phone number in specific format.

Mysql Phone Number Format

Mysql Phone Number Format is useful when you want to return the phone number in specific format.

Mysql Phone Number Format

Mysql Phone Number Format

     

Mysql Phone Number Format is useful when you want to return the phone number in specific format.

Understand with Example

The Tutorial illustrate an example from 'Mysql Phone Number Format'. To understand and grasp the example we use a create table query that is used to construct a table 'phoneno_format' with required fieldnames and datatypes respectively.

Query to create table named Phoneno_format:

mysql> create table Phoneno_format(name varchar(30),phone_no varchar(30));
Query OK, 0 rows affected (0.13 sec)

Query to insert data in table Phoneno_format:

The Query insert into add the required records values into the table 'Phoneno_format'.

mysql> insert into  Phoneno_format values ('Girish','05946224170'),
    ->  ('Komal','05946224177'),
    ->  ('Vikki','05946224178'),
    ->  ('Amit','05946224160');
Query OK, 4 rows affected (0.03 sec)
Records: 4  Duplicates: 0  Warnings: 0

Query to view data inserted in table Phoneno_format:

To view the records we run select query.

mysql> select * from  Phoneno_format
+--------+-------------+
| name   | phone_no    |
+--------+-------------+
| Girish | 05946224170 |
| Komal  | 05946224177 |
| Vikki  | 05946224178 |
| Amit   | 05946224160 |
+--------+-------------+
4 rows in set (0.00 sec)

Query to view phone_no in table Phoneno_format:

The Query below returns you the five left digit of the phone number as areacode and the right keyword in the query return the 6 digit no of the phone from the right as tel_number as fieldname from table phone_format.

mysql>   SELECT LEFT(phone_no,5) AS area_code,
    ->    RIGHT(phone_no,6) AS tel_number
    ->    from phoneno_format;

Output:-

+-----------+------------+
| area_code | tel_number |
+-----------+------------+
| 05946     | 224170     |
| 05946     | 224177     |
| 05946     | 224178     |
| 05946     | 224160     |
+-----------+------------+
4 rows in set (0.00 sec)