MySQL Query to change lower case to upper case?



You can use in-built function UPPER() from MySQL to change a lower case to upper case. The syntax is as follows with select statement.

SELECT UPPER(‘yourStringValue’);

The following is an example showing string in lower case −

mysql> select upper('john');

Here is the output displaying string in upper case −

+---------------+ | upper('john') | +---------------+ | JOHN          | +---------------+ 1 row in set (0.00 sec)

If you already have a table with a lower case value, then you can use the UPPER() function with update command. The syntax is as follows −

UPDATE yourTableName set yourColumnName = UPPER(yourColumnName);

To understand the above concept, let us first create a table and insert string values in lowercase. The following is the query to create a table −

mysql> create table UpperTableDemo    −> (    −> BookName longtext    −> ); Query OK, 0 rows affected (0.70 sec)

Insert some records in the table using INSERT command. The query is as follows −

mysql> insert into UpperTableDemo values('introduction to c'); Query OK, 1 row affected (0.13 sec) mysql> insert into UpperTableDemo values('introduction to java'); Query OK, 1 row affected (0.18 sec) mysql> insert into UpperTableDemo values('introduction to python'); Query OK, 1 row affected (0.11 sec) mysql> insert into UpperTableDemo values('introduction to c#'); Query OK, 1 row affected (0.17 sec)

Display all records from the table using select statement. The query is as follows −

mysql> select *from UpperTableDemo;

The following is the output −

+------------------------+ | BookName               | +------------------------+ | introduction to c      | | introduction to java   | | introduction to python | | introduction to c#     | +------------------------+ 4 rows in set (0.00 sec)

The following is the query to change the lower case to upper case −

mysql> update UpperTableDemo set BookName = upper(BookName); Query OK, 4 rows affected (0.16 sec) Rows matched: 4 Changed: 4 Warnings: 0

Display all records again with updated value. The query is as follows −

mysql> select *from UpperTableDemo;

The following is the output −

+------------------------+ | BookName               | +------------------------+ | INTRODUCTION TO C      | | INTRODUCTION TO JAVA   | | INTRODUCTION TO PYTHON | | INTRODUCTION TO C# | +------------------------+ 4 rows in set (0.00 sec)
Updated on: 2019-07-30T22:30:24+05:30

8K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements