In MySQL, the LCASE() function is a synonym for LOWER(). In other words, you can use either of these functions to do the same thing.
Specifically, both functions convert uppercase characters to lowercase, according to the current character set mapping (the default mapping is
utf8mb4
).Syntax
The syntax goes like this:
LCASE(str)
Where str is the string to be changed to lowercase.
Example
Here’s an example:
SELECT LCASE('CAT'), LOWER('CAT');
Result:
+--------------+--------------+ | LCASE('CAT') | LOWER('CAT') | +--------------+--------------+ | cat | cat | +--------------+--------------+
Binary Strings
These functions don’t work on binary strings. If you need to use them on a binary string, you’ll need to convert the string to a nonbinary string first. Here’s an example:
SET @str = BINARY 'Cat'; SELECT LCASE(@str) AS 'Binary', LCASE(CONVERT(@str USING utf8mb4)) AS 'Nonbinary';
Result:
+--------+-----------+ | Binary | Nonbinary | +--------+-----------+ | Cat | cat | +--------+-----------+
Using LCASE() in Views
One thing to be aware of is that, when the
LCASE()
function is used within a view, it is rewritten and stored as LOWER()
.
0 comments:
Post a Comment