Get field value and convert a particular character from it to uppercase with MySQL

MySQLMySQLi Database

Let us first create a table −

mysql> create table DemoTable1897
   (
   Name varchar(20)
   );
Query OK, 0 rows affected (0.00 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable1897 values('john');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1897 values('Chris');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1897 values('jace');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1897 values('David');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1897 values('Chris');
Query OK, 1 row affected (0.00 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable1897;

This will produce the following output −

+-------+
| Name  |
+-------+
| john  |
| Chris |
| jace  |
| David |
| Chris |
+-------+
5 rows in set (0.00 sec)

Here is the query to get field value and convert particular character into uppercasep

mysql> select replace(Name,'j','J') from DemoTable1897;

This will produce the following output −

+-----------------------+
| replace(Name,'j','J') |
+-----------------------+
| John                  |
| Chris                 |
| Jace                  |
| David                 |
| Chris                 |
+-----------------------+
5 rows in set (0.00 sec)
raja
Published on 27-Dec-2019 07:04:08
Advertisements