How the LOWER() function works in Mariadb?

The LOWER() function is a string function that returns a string with all the characters converted to lowercase.

Posted on

The LOWER() function is a string function that returns a string with all the characters converted to lowercase. The LOWER() function is case-insensitive by default, unless the collation of the string argument is case-sensitive. The LOWER() function is useful for performing various operations, such as comparison, sorting, searching, etc.

Syntax

The syntax of the LOWER() function is as follows:

LOWER(string)

The string argument is the string to be converted to lowercase. The string argument can be any valid string expression, such as a column name, a literal value, a function call, etc.

The LOWER() function returns a string value that is the lowercase version of the string argument. If the string argument is NULL, the function returns NULL.

Examples

Example 1: Basic usage of the LOWER() function

The following example shows how to use the LOWER() function with a simple string. It returns the lowercase version of the string ‘Hello World’.

SELECT LOWER('Hello World');

The output is:

hello world

This means that the LOWER() function converts all the uppercase characters in the string ‘Hello World’ to lowercase.

Example 2: Using the LOWER() function with a column name

The following example shows how to use the LOWER() function with a column name. It returns the lowercase version of the values in the name column of the employees table.

SELECT LOWER(name) FROM employees;

The output is:

alice
bob
charlie
david
eve

This means that the LOWER() function converts all the uppercase characters in the values of the name column to lowercase.

Example 3: Using the LOWER() function with a function call

The following example shows how to use the LOWER() function with a function call. It returns the lowercase version of the current user name.

SELECT LOWER(USER());

The output is:

root@localhost

This means that the LOWER() function converts all the uppercase characters in the result of the USER() function to lowercase.

There are some other functions that are related to the LOWER() function in Mariadb. They are:

  • UPPER(): This function returns a string with all the characters converted to uppercase. It is the opposite of the LOWER() function, meaning that UPPER(LOWER(x)) = UPPER(x) for any string x.
  • LCASE(): This function is a synonym for the LOWER() function. It has the same syntax and behavior as the LOWER() function.
  • UCASE(): This function is a synonym for the UPPER() function. It has the same syntax and behavior as the UPPER() function.

Here are some examples of using these related functions:

-- Get the uppercase version of 'Hello World'
SELECT UPPER('Hello World');

-- Get the lowercase version of 'Hello World'
SELECT LCASE('Hello World');

-- Get the uppercase version of 'Hello World'
SELECT UCASE('Hello World');

Conclusion

In this article, we have learned how the LOWER() function works in Mariadb. We have seen its syntax, examples, and related functions. We have also learned how to use the LOWER() function to convert a string to lowercase. The LOWER() function is a useful function to perform various operations, such as comparison, sorting, searching, etc.