Home > Database > Mysql Tutorial > MySQL query to change lowercase to uppercase?

MySQL query to change lowercase to uppercase?

WBOY
Release: 2023-09-05 13:25:02
forward
1009 people have browsed it

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’);
Copy after login

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

mysql> select upper('john');
Copy after login

This is the output to display a string in uppercase -

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

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);
Copy after login

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)
Copy after login

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)
Copy after login

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

mysql> select *from UpperTableDemo;
Copy after login
Copy after login

Below is the output -

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

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
Copy after login

Display all the records again and update the values. The query is as follows -

mysql> select *from UpperTableDemo;
Copy after login
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template