SQL Standard

SQL Lowercase

Strings refer to a series of characters organized in a specific order. Strings or string objects are inevitable in programming and, more specifically, database administration. They allow us to store information, such as names, places, and money.

Therefore, learning how to work with strings is very important. This article will teach you how to convert a string to lowercase using Standard SQL.

SQL Lower Function

The Lower function in Standard SQL allows you to convert a string to lowercase. The function syntax is as shown:

LOWER(VALUE);

The function takes the string as an argument and returns the string with all the alphabetic characters converted to lowercase.

Take the example shown below:

SELECT LOWER('LINUXHINT');

The previous query should return the specified string in lowercase.

+-----------+
| LOWER     |
+-----------+
| linuxhint |
+-----------+

Even if a string contains a mix of lowercase and uppercase characters, it will return lowercase results.

WITH
    strings AS (
        SELECT
            'LINUXHINT' AS str
        UNION ALL
        SELECT
            'FO0' AS str
        UNION ALL
        SELECT
            'BaR' AS str
    )
SELECT
    LOWER(str) AS RESULT
FROM
    strings;

The previous example statements should return all the strings converted to lowercase as shown below:

  RESULT
-----------
 linuxhint
 fo0
 bar

Note that the numeric characters do not affect the output.

SQL Update Existing Record to Uppercase

We can update an existing record to lowercase, as shown in the example below:

UPDATE TABLE_NAME SET field_name = LOWER(field_name);

This should update the specified field value to lowercase.

Conclusion

This tutorial covered how to convert a string to lowercase using the Standard SQL Lower function. Most database engines adopt the lower function. However, you may find it under a different name, such as LCASE (Oracle), in some instances. Thanks for reading this article, and we hope you found it helpful. Check the other Linux Hint articles for more tips and tutorials.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list