Tuesday, 30 July 2019

How to Convert Uppercase Characters to Lowercase in MySQL

In MySQL, you can use the LOWER() function to convert any uppercase characters to lowercase. Alternatively, you can use the LCASE() function, which is a synonym for LOWER().
The syntax goes like this:
LOWER(str)
Or…
LCASE(str)
Where str is the string you want converted to lowercase.

Example

Here’s an example:
SELECT LOWER('ATTENTION');
Result:
+--------------------+
| LOWER('ATTENTION') |
+--------------------+
| attention          |
+--------------------+
Of course, if the string already contains any lowercase characters, then they will remain lowercase.
Example:
SELECT LOWER('Attention');
Result:
+--------------------+
| LOWER('ATTENTION') |
+--------------------+
| attention          |
+--------------------+

Database Example

Here’s an example of selecting data from a database and converting it to lowercase:
USE Music;
SELECT 
    ArtistName AS Original, 
    LOWER(ArtistName) AS Lowercase
FROM Artists
LIMIT 5;
Result:
+------------------+------------------+
| Original         | Lowercase        |
+------------------+------------------+
| Iron Maiden      | iron maiden      |
| AC/DC            | ac/dc            |
| Allan Holdsworth | allan holdsworth |
| Buddy Rich       | buddy rich       |
| Devin Townsend   | devin townsend   |
+------------------+------------------+
The UPPER() and UCASE() functions work the same way to convert characters to uppercase.

0 comments:

Post a Comment