Replace dot with comma on MySQL SELECT?

MySQLMySQLi Database

To replace dot with comma on SELECT, you can use REPLACE().

 Following is the syntax −

select replace(yourColumnName, '.' , ',' ) from yourTableName;

Let us first create a table −

mysql> create table DemoTable
(
   Value float
);
Query OK, 0 rows affected (0.63 sec)

Insert records in the table using insert command −

mysql> insert into DemoTable values(4.56);
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable values(456.23);
Query OK, 1 row affected (0.12 sec)
mysql> insert into DemoTable values(1078.3);
Query OK, 1 row affected (0.22 sec)
mysql> insert into DemoTable values(2000.50);
Query OK, 1 row affected (0.26 sec)
mysql> insert into DemoTable values(78.99);
Query OK, 1 row affected (0.16 sec)

Display records from the table using select command −

mysql> select *from DemoTable;

This will produce the following output −

+--------+
| Value  |
+--------+
| 4.56   |
| 456.23 |
| 1078.3 |
| 2000.5 |
| 78.99  |
+--------+
5 rows in set (0.00 sec)

Following is the query to replace dot with comma on SELECT −

mysql> select replace(Value,'.',',') from DemoTable;

This will produce the following output −

+------------------------+
| replace(Value,'.',',') |
+------------------------+
| 4,56                   |
| 456,23                 |
| 1078,3                 |
| 2000,5                 |
| 78,99                  |
+------------------------+
5 rows in set (0.07 sec)
raja
Published on 29-Apr-2019 12:03:30
Advertisements