MySQL LOWER() Function

The LOWER() function in MySQL is used to convert a string to lowercase.


Syntax

LOWER(text)

Parameters

Parameter Description
text Required. The string to convert to lowercase.

Definition and Use

  • Purpose: Converts all characters in a string to lowercase.
  • Behavior:
    • The function changes all uppercase letters (A-Z) to lowercase (a-z).
    • Non-alphabetic characters (e.g., numbers, punctuation) remain unaffected.
  • Note: The LCASE() function is synonymous with the LOWER() function in MySQL. Both functions perform the same operation.

Usage Examples

Example 1: Basic Usage

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

SELECT LOWER("SQL Tutorial is FUN!");

Output:

LOWER("SQL Tutorial is FUN!")
sql tutorial is fun!

Explanation: All letters in the string are converted to lowercase.


Example 2: Convert Text in a Column to Lowercase

Convert the text in the CustomerName column to lowercase:

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

Output (example data):

CustomerName LowercaseCustomerName
John Smith john smith
Alice Brown alice brown

Explanation: Each customer's name is displayed in lowercase.


Technical Details

  • Availability: Available from MySQL 4.0 onwards.
  • Return Type: Returns a string with all alphabetic characters converted to lowercase.
  • Case Sensitivity: Converts only uppercase alphabetic characters to lowercase.

Applications

  1. Standardizing Case: Often used to standardize string values, ensuring case-insensitive comparisons or sorting.
  2. Data Cleaning: Helpful in cleaning data, especially when dealing with case discrepancies in user input.
  3. Text Processing: Used in applications that require uniformity, like searching, sorting, or grouping text fields without worrying about case differences.

Related Functions

  • UPPER(): Converts all characters in a string to uppercase.
  • LCASE(): Synonym for LOWER(), also converts text to lowercase.

Key Notes

  • The LOWER() function is ideal for case-insensitive operations such as searching or sorting where the case of the characters does not matter.
  • This function operates on character data types, and may return NULL if the input string is NULL.

The LOWER() function is a simple yet powerful tool for ensuring that text is in lowercase format, which can be essential for data normalization, comparison, and searching.


Was this article helpful?