Home  >  Article  >  Database  >  MySQL query to change lowercase to uppercase?

MySQL query to change lowercase to uppercase?

WBOY
WBOYforward
2023-09-05 13:25:02969browse

MySQL query to change lowercase to uppercase?

You can change lowercase letters to uppercase letters using MySQL's built-in function UPPER(). The syntax is as follows, with select statements.

SELECT UPPER(‘yourStringValue’);

The following is an example to display a string in lowercase -

mysql> select upper('john');

This is the output to display a string in uppercase -

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

If you already have a string with lowercase values table, you can use the UPPER() function with the update command. The syntax is as follows -

UPDATE yourTableName set yourColumnName = UPPER(yourColumnName);

To understand the above concept, we first create a table and insert lowercase string values. Following is the query to create the table -

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

Use INSERT command to insert some records in the table. 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)

Use the select statement to display all records in the table. The query is as follows -

mysql> select *from UpperTableDemo;

Below is the output -

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

Below is the query to change lowercase to uppercase -

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

Display all the records again and update the values. 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 above is the detailed content of MySQL query to change lowercase to uppercase?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete