How do I replace “+”(plus sign) with SPACE in MySQL?


To replace, use REPLACE() function from MySQL. Let us first create a table −

mysql> create table DemoTable
(
   Number varchar(100)
);
Query OK, 0 rows affected (0.86 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values('+916578675547');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable values('+918976676564');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable values('+919800087678');
Query OK, 1 row affected (0.12 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output −

+---------------+
| Number        |
+---------------+
| +916578675547 |
| +918976676564 |
| +919800087678 |
+---------------+
3 rows in set (0.00 sec)

Following is the query to replace “+”(plus sign) with SPACE −

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

Let us check the table records once again −

mysql> select *from DemoTable

This will produce the following output −

+---------------+
| Number        |
+---------------+
| 916578675547 |
| 918976676564 |
| 919800087678 |
+---------------+
3 rows in set (0.00 sec)

Updated on: 25-Sep-2019

337 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements