Friday, December 20, 2024

MySQL LCASE() Function

 The LCASE() function in MySQL is used to convert a given string to lowercase. It is a string function that takes a string argument and returns the string with all characters in lowercase.

Syntax:

LCASE(string)
  • string: The string expression you want to convert to lowercase.

Example Usage:

  1. Basic Example:

    SELECT LCASE('Hello World');
    

    Result:

    hello world
    
  2. Using with a Column: If you have a table with a column of strings and want to convert all the values in that column to lowercase, you can use LCASE() in a SELECT query.

    SELECT LCASE(name) FROM employees;
    

    This will return all the values in the name column converted to lowercase.

  3. With WHERE Clause: You can use LCASE() in the WHERE clause to perform case-insensitive searches.

    SELECT * FROM employees WHERE LCASE(name) = 'john doe';
    

    This ensures the search is case-insensitive, matching 'John Doe', 'john doe', etc.

Notes:

  • LCASE() is an alias for LOWER() in MySQL, so both functions work the same way.
  • It only affects alphabetic characters and does not modify numbers or special characters.

No comments:

Post a Comment