本文翻译自:MySQL - How to select data by string length
SELECT * FROM table ORDER BY string_length(column);
是否有MySQL函数可以执行此操作(当然不是string_length
)?
#1楼
参考:https://stackoom.com/question/7QIp/MySQL-如何通过字符串长度选择数据
#2楼
看一下有关字符串函数的MySQL文档 ,我们还可以使用CHAR_LENGTH()
和CHARACTER_LENGTH()
。
#3楼
You are looking for CHAR_LENGTH()
to get the number of characters in a string. 您正在寻找CHAR_LENGTH()
以获取字符串中的字符数。
For multi-byte charsets LENGTH()
will give you the number of bytes the string occupies, while CHAR_LENGTH()
will return the number of characters. 对于多字节字符集, LENGTH()
将为您提供字符串占用的字节数,而CHAR_LENGTH()
将返回字符数。
#4楼
select * from table order by length(column);
有关length()函数以及所有其他字符串函数的文档,请参见此处 。
#5楼
我用来查找字符串length
的函数是length
,用法如下:
SELECT * FROM table ORDER BY length(column);
#6楼
select * from *tablename* where 1 having length(*fieldname*)=*fieldlength*
例如,如果您想从客户中选择名称短于2个字符的条目。
select * from customer where 1 **having length(name)<2**