Home > Database > Mysql Tutorial > What MySQL functions can we use to change the character case of a string?

What MySQL functions can we use to change the character case of a string?

PHPz
Release: 2023-09-08 21:33:03
forward
704 people have browsed it

我们可以使用哪些 MySQL 函数来更改字符串的字符大小写?

We can use the LCASE() and LOWER() functions to change the character case of the string to lowercase, and use the UCASE() and UPPER() functions to change the character case of the string to lower case. Change to uppercase.

Example

mysql> Select LCASE('NEW DELHI');

+--------------------+
| LCASE('NEW DELHI') |
+--------------------+
| new delhi          |
+--------------------+

1 row in set (0.00 sec)

mysql> Select LOWER('NEW DELHI');

+--------------------+
| LOWER('NEW DELHI') |
+--------------------+
| new delhi          |
+--------------------+

1 row in set (0.00 sec)

mysql> Select UCASE('new delhi');

+--------------------+
| UCASE('new delhi') |
+--------------------+
| NEW DELHI          |
+--------------------+

1 row in set (0.00 sec)

mysql> Select UPPER('new delhi');

+--------------------+
| UPPER('new delhi') |
+--------------------+
| NEW DELHI          |
+--------------------+

1 row in set (0.00 sec)
Copy after login

We can also use these functions with columns of tables. For example, suppose we want to change the character case of values ​​in a column in the output, then the following query on the table "Student" can demonstrate it -

mysql> Select Name, UCASE(Name) from student;

+---------+-------------+
| Name    | UCASE(Name) |
+---------+-------------+
| Gaurav  | GAURAV      |
| Aarav   | AARAV       |
| Harshit | HARSHIT     |
| Gaurav  | GAURAV      |
| Yashraj | YASHRAJ     |
+---------+-------------+

5 rows in set (0.00 sec)

mysql> Select Name, LCASE(Name) from student;

+---------+-------------+
| Name    | LCASE(Name) |
+---------+-------------+
| Gaurav  | gaurav      |
| Aarav   | aarav       |
| Harshit | harshit     |
| Gaurav  | gaurav      |
| Yashraj | yashraj     |
+---------+-------------+

5 rows in set (0.00 sec)

mysql> Select Name, UPPER(Name) from student;

+---------+-------------+
| Name    | UPPER(Name) |
+---------+-------------+
| Gaurav  | GAURAV      |
| Aarav   | AARAV       |
| Harshit | HARSHIT     |
| Gaurav  | GAURAV      |
| Yashraj | YASHRAJ     |
+---------+-------------+

5 rows in set (0.00 sec)

mysql> Select Name, LOWER(Name) from student;

+---------+-------------+
| Name    | LOWER(Name) |
+---------+-------------+
| Gaurav  | gaurav      |
| Aarav   | aarav       |
| Harshit | harshit     |
| Gaurav  | gaurav      |
| Yashraj | yashraj     |
+---------+-------------+

5 rows in set (0.00 sec)
Copy after login

The above is the detailed content of What MySQL functions can we use to change the character case of a string?. 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