MySQL 将列的所有值更新为小写
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6160873/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Update all values of a column to lowercase
提问by Adam Ramadhan
Lets say I have something like this
可以说我有这样的事情
uid tag
1 HeLLo
2 heLLO
3 HELLO
4 hello
How can I update all values in the "tag" column to:
如何将“标签”列中的所有值更新为:
uid tag
1 hello
2 hello
3 hello
4 hello
using MySQL?
使用 MySQL?
回答by Rippo
See http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_lower
见http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_lower
UPDATE table_name SET tag = LOWER(tag)
回答by Susie
Version for case-insensitive matching and including a "WHERE" clause if you don't want to update the entire column:
如果您不想更新整个列,则不区分大小写匹配并包含“WHERE”子句的版本:
UPDATE table
SET tag = LOWER(tag)
WHERE LOWER(tag) != tag
COLLATE Latin1_General_CS_AS
The COLLATE line will make it work if your database uses case insensitive matching, as mine does.
如果您的数据库使用不区分大小写的匹配,则 COLLATE 行将使其工作,就像我的一样。
回答by Anjani Barnwal
Try this:
尝试这个:
update `table` set `column_name` = LOWER(column_name without quotation)