php 是否有将字符串转换为小写的 MySQL 命令?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/221774/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 21:58:16  来源:igfitidea点击:

Is there a MySQL command to convert a string to lowercase?

phpmysql

提问by Thomas Owens

I have a MySQL database of keywords that are presently mixed-case. However, I want to convert them all to lowercase. Is there an easy command to do this, either using MySQL or MySQL and PHP?

我有一个目前大小写混合的关键字的 MySQL 数据库。但是,我想将它们全部转换为小写。是否有一个简单的命令来执行此操作,无论是使用 MySQL 还是 MySQL 和 PHP?

回答by Paul Dixon

UPDATE table SET colname=LOWER(colname);

回答by Jon Grant

Yes, the function is LOWER() or LCASE() (they both do the same thing).

是的,函数是 LOWER() 或 LCASE() (它们都做同样的事情)。

For example:

例如:

select LOWER(keyword) from my_table

回答by Greg

SELECT LOWER(foo) AS foo FROM bar

SELECT LOWER(foo) AS foo FROM bar

回答by dmanxiii

You can use the functions LOWER() or LCASE().

您可以使用函数 LOWER() 或 LCASE()。

These can be used both on columns or string literals. e.g.

这些可以用于列或字符串文字。例如

SELECT LOWER(column_name) FROM table a;

or

或者

SELECT column_name FROM table a where column = LOWER('STRING')

LCASE() can be substituted for LOWER() in both examples.

在两个示例中,LCASE() 都可以替换为 LOWER()。

回答by myplacedk

Did you try looking it up? Google, manual...

你试过查一下吗?谷歌,手动...

http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_lower

http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_lower

mysql> SELECT LOWER('QUADRATICALLY');
        -> 'quadratically'

回答by Vi8L

Simply use:

只需使用:

UPDATE `tablename` SET `colnameone`=LOWER(`colnameone`);  

or

或者

UPDATE `tablename` SET `colnameone`=LCASE(`colnameone`);

Both functions will work the same.

这两个功能的工作方式相同。

回答by HD FrenchFeast

Interesting to note that the field name is renamed and if you reference it in a function, you will not get its value unless you give him an alias (that can be its own name)

有趣的是,字段名被重命名,如果你在函数中引用它,除非你给他一个别名(可以是它自己的名字),否则你不会得到它的值

Example: I use a function to dynamically get a field name value:

示例:我使用一个函数来动态获取字段名称值:

function ColBuilder ($field_name) {
…
While ($result = DB_fetch_array($PricesResult)) {
$result[$field_name]
}
…
}

my query being: SELECT LOWER(itemID), … etc..

我的查询是:SELECT LOWER(itemID), ... 等等。

needed to be changed to: SELECT LOWER(itemID) as itemID, … etc..

需要更改为:SELECT LOWER(itemID) as itemID,...等。

回答by uma

use LOWERfunction to convert data or string in lower case.

使用LOWER函数将数据或字符串转换为小写。

select LOWER(username) from users;

or

或者

select * from users where LOWER(username) = 'vrishbh';

回答by Rodent43

I believe in php you can use

我相信你可以使用 php

strtolower() 

so you could make a php to read all the entries in the table then use that command to print them back as lower case

所以你可以制作一个 php 来读取表中的所有条目,然后使用该命令将它们打印回小写