在 MySQL 中查询特定长度的字符串字段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4940873/
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-31 18:40:48 来源:igfitidea点击:
Query in MySQL for string fields with a specific length
提问by ana
How can I make a MySQL query asking for all the string fields in a column that have a particular length?
如何进行 MySQL 查询,要求列中具有特定长度的所有字符串字段?
Thanks!
谢谢!
回答by BoltClock
Use LENGTH()
for checking length in bytes:
使用LENGTH()
的字节长度检查:
SELECT str FROM sometable WHERE LENGTH(str) = 5;
Or CHAR_LENGTH()
for checking length in number of characters (useful for multi-byte strings):
或者CHAR_LENGTH()
检查字符数的长度(对于多字节字符串很有用):
SELECT str FROM sometable WHERE CHAR_LENGTH(str) = 5;
回答by John K.
select *
from myTable
where length(myColumn) = 5