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:
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:
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.
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:
-----------
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:
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.