MySQL - LCASE() Function



The MySQL LCASE() function is used to convert a string value to all lower case letters.

It is equivalent to the LOWER() function in MySQL. This function can be useful in various scenarios such as formatting text for consistent comparisons, normalization, etc.

Syntax

Following is the syntax of MySQL LCASE() function −

LCASE(str)

Parameters

This function takes a string value as a parameter.

Return Value

This function returns the lowercase version of the given string.

Example

In the following example, we are converting the string 'TUTORIALSPOINT' to all lowercase letters −

SELECT LCASE('TUTORIALSPOINT');

Following is the output of the above code −

LCASE('TUTORIALSPOINT')
tutorialspoint

Example

To change the case of a binary string from upper to lower, you first need to convert it into a non-binary string and then proceed −

SELECT LCASE(CONVERT(BINARY 'TUTORIALSPOINT' USING utf8mb4));

The output obtained is as follows −

LCASE(CONVERT(BINARY 'TUTORIALSPOINT' USING utf8mb4))
tutorialspoint

Example

If the argument passed to the LCASE() function is NULL, it returns NULL −

SELECT LCASE(NULL);

We get the output as follows −

LCASE(NULL)
0x

Example

If you pass a numerical value to this function, it returns the same value −

SELECT LCASE(55886);

The result produced is as shown below −

LCASE(55886)
55886

Example

You can also convert the upper case letters in the column of a table to lower case using the LCASE() function.

Let us create a table named "EMP" and insert records into it using CREATE and INSERT statements as shown below −

CREATE TABLE EMP(
   FIRST_NAME  CHAR(20) NOT NULL,
   LAST_NAME  CHAR(20),
   AGE INT,
   INCOME FLOAT
);

Now, let us insert records into it using the INSERT statement −

INSERT INTO EMP VALUES 
('Krishna', 'Sharma', 19, 2000),
('Raj', 'Kandukuri', 20, 7000),
('Ramya', 'Ramapriya', 25, 5000),
('Mac', 'Mohan', 26, 2000);

The EMP obtained is as follows −

FIRST_NAME LAST_NAME AGE INCOME
Krishna Sharma 19 2000
Raj Kandukuri 20 7000
Ramya Ramapriya 25 5000
Mac Mohan 26 2000

Following query converts all the characters in the column 'FIRST_NAME' using the LCASE() function −

SELECT FIRST_NAME, LAST_NAME, AGE, LCASE(FIRST_NAME) as RESULT 
FROM EMP;

After executing the above code, we get the following output −

FIRST_NAME LAST_NAME AGE RESULT
Krishna Sharma 19 krishna
Raj Kandukuri 20 raj
Ramya Ramapriya 25 ramya
Mac Mohan 26 mac
mysql-lcase-function.htm
Advertisements