MySQL 的 LOWER()
函数将字符串中的所有字母字符转换为小写字母字符。与该方法相对应的是 UPPER()
函数,其正好相反,将字符串转换为大写。如果字符串中有不是字母的字符,则不受此函数的影响。
语法
语句如下:
LOWER(str)
参数定义如下:
str
:需要转换为小写的字符串。
LOWER 函数将使用当前字符集映射(默认为 latin1)转换字符。
LOWER 函数从 MySQL 3.23 版本(包括)开始支持。
LOWER 函数有同样作用的函数 LCASE。
示例
SELECT LOWER('MYTESTSTRING');
具体输出如下:
mysql> SELECT LOWER('MYTESTSTRING');
+-----------------------+
| LOWER('MYTESTSTRING') |
+-----------------------+
| myteststring |
+-----------------------+
1 row in set (0.01 sec)
将指定的字段值转换为小写,假设有 publisher 表,表的样本数据如下:
+--------+------------------------------+-----------+-----------+----------------+--------------+------------+ | pub_id | pub_name | pub_city | country | country_office | no_of_branch | estd | +--------+------------------------------+-----------+-----------+----------------+--------------+------------+ | P001 | Jex Max Publication | New York | USA | New York | 15 | 1969-12-25 | | P002 | BPP Publication | Mumbai | India | New Delhi | 10 | 1985-10-01 | | P003 | New Harrold Publication | Adelaide | Australia | Sydney | 6 | 1975-09-05 | | P004 | Ultra Press Inc. | London | UK | London | 8 | 1948-07-10 | | P005 | Mountain Publication | Houstan | USA | Sun Diego | 25 | 1975-01-01 | | P006 | Summer Night Publication | New York | USA | Atlanta | 10 | 1990-12-10 | | P007 | Pieterson Grp. of Publishers | Cambridge | UK | London | 6 | 1950-07-15 | | P008 | Novel Publisher Ltd. | New Delhi | India | Bangalore | 10 | 2000-01-01 | +--------+------------------------------+-----------+-----------+----------------+--------------+------------+
执行如下代码:
SELECT pub_name,LOWER(pub_name)
FROM publisher
WHERE country<>'USA';
执行后,输出如下:
mysql> SELECT pub_name,LOWER(pub_name)
-> FROM publisher
-> WHERE country<>'USA';
+------------------------------+------------------------------+
| pub_name | LOWER(pub_name) |
+------------------------------+------------------------------+
| BPP Publication | bpp publication |
| New Harrold Publication | new harrold publication |
| Ultra Press Inc. | ultra press inc. |
| Pieterson Grp. of Publishers | pieterson grp. of publishers |
| Novel Publisher Ltd. | novel publisher ltd. |
+------------------------------+------------------------------+
5 rows in set (0.00 sec)