MySQL query to format numbers which has space between digit?


Let us first create a table −

mysql> create table DemoTable1546
   -> (
   -> Number varchar(20)
   -> );
Query OK, 0 rows affected (0.99 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable1546 values('145 78 90');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable1546 values('89 789 564 903');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable1546 values('1345 7894 866 653534');
Query OK, 1 row affected (0.12 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable1546;

This will produce the following output −

+----------------------+
| Number               |
+----------------------+
| 145 78 90            |
| 89 789 564 903       |
| 1345 7894 866 653534 |
+----------------------+
3 rows in set (0.00 sec)

Following is the query to format numbers by replacing space between numbers −

mysql> update DemoTable1546 set Number=replace(Number,' ','');
Query OK, 3 rows affected (0.13 sec)
Rows matched: 3  Changed: 3 Warnings: 0

Let us check the table records once again −

mysql> select * from DemoTable1546;

This will produce the following output −

+-------------------+
| Number            |
+-------------------+
| 1457890           |
| 89789564903       |
| 13457894866653534 |
+-------------------+
3 rows in set (0.00 sec)

Updated on: 12-Dec-2019

185 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements