To set country code to phone numbers would mean to concatenate. You can use CONCAT() for this.
Let us first create a table −
mysql> create table DemoTable769 (MobileNumber varchar(100)); Query OK, 0 rows affected (0.54 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable769 values('8799432434'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable769 values('9899996778'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable769 values('7890908989'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable769 values('9090898987'); Query OK, 1 row affected (0.20 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable769;
This will produce the following output -
+--------------+ | MobileNumber | +--------------+ | 8799432434 | | 9899996778 | | 7890908989 | | 9090898987 | +--------------+ 4 rows in set (0.00 sec)
Following is the query to set country code to column values with phone numbers in MySQL −
mysql> update DemoTable769 set MobileNumber=concat('+91',MobileNumber); Query OK, 4 rows affected (0.20 sec) Rows matched: 4 Changed: 4 Warnings: 0
Let us check the description of the view −
mysql> select *from DemoTable769;
This will produce the following output -
+---------------+ | MobileNumber | +---------------+ | +918799432434 | | +919899996778 | | +917890908989 | | +919090898987 | +---------------+ 4 rows in set (0.00 sec)