MySQL LOWER Function
Summary: in this tutorial, you will learn how to use the MySQL LOWER(
) function to return the lowercase of a string.
MySQL LOWER()
function overview
The LOWER()
function accepts a string argument and returns the lowercase version of that string.
Here is the syntax of the LOWER()
function:
LOWER(str)
Code language: SQL (Structured Query Language) (sql)
In this syntax, the str
is the argument that you want to convert to the lowercase.
Alternatively, you can use the LCASE()
function which returns the same result:
LCASE(str)
Code language: SQL (Structured Query Language) (sql)
Note that to convert a string to uppercase, you use the UPPER()
function.
MySQL LOWER()
function examples
Let’s take some examples of using the MySQL LOWER()
function.
A) Using MySQL LOWER()
to convert a literal string to lowercase
This example uses the LOWER()
function to convert the string MySQL to lowercase:
SELECT
LOWER('MySQL')
Code language: SQL (Structured Query Language) (sql)
Here is the output:
+----------------+
| LOWER('MySQL') |
+----------------+
| mysql |
+----------------+
1 row in set (0.00 sec)
Code language: JavaScript (javascript)
B) Using MySQL LOWER()
to with data in the table
See the following employees
table from the sample database:
This example uses the LOWER()
function to convert the first name of employees to lowercase.
SELECT
firstname,
LOWER(firstname) lowercase
FROM
employees
ORDER BY
firstname
LIMIT 10;
Code language: SQL (Structured Query Language) (sql)
The following picture shows the output:
Dealing with binary string data
The LOWER()
function is not effective when applied to the binary string data such as BINARY
, VARBINARY
, and BLOB
. Therefore, before passing this data to the LOWER()
function, you need to convert the string to nonbinary string.
See the following example:
SET @str = BINARY 'BINARY STRING';
SELECT LOWER(@str), LOWER(CONVERT(@str USING utf8mb4));
Code language: SQL (Structured Query Language) (sql)
Here is the output:
+---------------+---------------+
| LOWER(@str) | lower_case |
+---------------+---------------+
| BINARY STRING | binary string |
+---------------+---------------+
1 row in set (0.00 sec)
Code language: JavaScript (javascript)
As you can see clearly from the output, the LOWER()
function has no effect on the binary string.
In this tutorial, you have learned how to use the MySQL LOWER()
function to convert a string to lowercase.