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
PHPzforward
2023-09-08 21:33:03698browse

我们可以使用哪些 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)

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)

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!

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