Home  >  Article  >  Database  >  How to convert string to lowercase in mysql

How to convert string to lowercase in mysql

青灯夜游
青灯夜游Original
2021-12-31 17:09:037847browse

Mysql method to convert a string to lowercase: 1. Use the LOWER() function, the syntax "SELECT LOWER(str) [FROM data table name];"; 2. Use the LCASE() function, the syntax " SELECT LCASE(str) [FROM data table name];".

How to convert string to lowercase in mysql

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

mysql converts strings to lowercase

1. Use the LOWER() function

The alphabetic lowercase conversion function LOWER(str) can convert all alphabetic characters in the string to lowercase.

SELECT LOWER(column_name) [FROM table_name];

Example 1: Use the LOWER function to convert all alphabetic characters in the string to lowercase

mysql> SELECT LOWER('BLUE'),LOWER('Blue');
+---------------+---------------+
| LOWER('BLUE') | LOWER('Blue') |
+---------------+---------------+
| blue          | blue          |
+---------------+---------------+
1 row in set (0.03 sec)

As you can see from the results, all the letters that were originally uppercase are converted to lowercase, such as "BLUE", after conversion, becomes "blue"; a string with mixed uppercase and lowercase letters, the lowercase remains unchanged, and the uppercase letters are converted to lowercase letters, such as "Blue", after conversion, it becomes "bule".

Example 2: Convert the text in "CustomerName" to lowercase

SELECT LCASE(CustomerName) AS LowercaseCustomerName
FROM Customers;

2. Use the LCASE() function

LCASE( ) is a synonym for LOWER().

LCASE() function converts the field value to lowercase.

SELECT LCASE(str) [FROM table_name];

Example: Convert the text in "CustomerName" to lowercase

SELECT LCASE(CustomerName) AS LowercaseCustomerName
FROM Customers;

[Related recommendations: mysql video tutorial]

The above is the detailed content of How to convert string to lowercase in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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