在MySQL中查询具有特定长度的字符串字段

时间:2021-09-01 22:18:49

How can I make a MySQL query asking for all the string fields in a column that have a particular length?

如何创建MySQL查询,询问列中具有特定长度的所有字符串字段?

Thanks!

谢谢!

2 个解决方案

#1


57  

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;

#2


4  

select * 
from myTable 
where length(myColumn) = 5

#1


57  

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;

#2


4  

select * 
from myTable 
where length(myColumn) = 5