MySQL LCASE() Function

The LCASE() function in MySQL is used to convert all characters in a given string to lowercase. This function is synonymous with the LOWER() function.


Syntax

LCASE(text)

Parameters

Parameter Description
text Required. The string to convert.

Definition and Use

  • Purpose: Converts a string to lowercase.
  • Behavior:
    • If the input is already in lowercase, the string remains unchanged.
    • If the input string contains non-alphabetic characters, they are not affected.

Usage Examples

Example 1: Basic Conversion

Convert the string "SQL Tutorial is FUN!" to lowercase:

SELECT LCASE("SQL Tutorial is FUN!") AS LowercaseText;

Output:

LowercaseText
sql tutorial is fun!

Example 2: Lowercase Conversion in a Column

Convert all values in the CustomerName column to lowercase:

SELECT CustomerName, LCASE(CustomerName) AS LowercaseCustomerName
FROM Customers;

Output (example data):

CustomerName LowercaseCustomerName
John Smith john smith
Alice Brown alice brown

Example 3: Lowercase Conversion with NULL Values

If the input is NULL, the function returns NULL:

SELECT LCASE(NULL) AS LowercaseText;

Output:

LowercaseText
NULL

Technical Details

  • Availability: Available from MySQL 4.0 onwards.
  • Return Type: Returns a string with all characters in lowercase.

Applications

  1. Standardizing Data: Ensure uniform case for text data, such as emails or usernames.
  2. Case-Insensitive Comparisons: Use LCASE() to prepare strings for case-insensitive matching or comparisons.
  3. Text Transformation: Format data for display or reporting.

Key Notes

  • The function does not modify non-alphabetic characters, such as numbers, punctuation, or special symbols.
  • Use LCASE() when working with English or similar alphabetic scripts. For locale-sensitive transformations, consider Unicode-specific methods.
  • The function is often used in conjunction with UPPER() (or UCASE()) for case normalization tasks.

The LCASE() function is a simple yet powerful tool for transforming text to lowercase in MySQL, making it ideal for tasks requiring standardized or normalized text.


Was this article helpful?