Add Separator to Numbers Using MySQL Views



Let us first create a table −

mysql> create table DemoTable
(
   StudentId int
);
Query OK, 0 rows affected (0.62 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values(343898456);
Query OK, 1 row affected (0.20 sec)
mysql> insert into DemoTable values(222333444);
Query OK, 1 row affected (0.22 sec)

Following is the query to display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output −

+-----------+
| StudentId |
+-----------+
| 343898456 |
| 222333444 |
+-----------+
2 rows in set (0.00 sec)

Here is the query to create view −

mysql> create view myView_DemoTable as select format(StudentId, 0) AS `StudentId` from DemoTable;
Query OK, 0 rows affected (0.18 sec)
Let us check the records of view table:
mysql> select *from myView_DemoTable;

This will produce the following output −

+-------------+
| StudentId   |
+-------------+
| 343,898,456 |
| 222,333,444 |
+-------------+
2 rows in set (0.04 sec)
Updated on: 2019-07-30T22:30:25+05:30

159 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements