MySQL - 如何按字符串长度选择数据
SELECT * FROM table ORDER BY string_length(column);
是否有 MySQL 函数可以执行此操作(当然不是 string_length
)?
SELECT * FROM table ORDER BY string_length(column);
Is there a MySQL function to do this (of course instead of string_length
)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您正在寻找
CHAR_LENGTH()< /code>
获取字符串中的字符数。
对于多字节字符集
LENGTH()
将给出字符串占用的字节数,而
CHAR_LENGTH()
将返回字符数。You are looking for
CHAR_LENGTH()
to get the number of characters in a string.For multi-byte charsets
LENGTH()
will give you the number of bytes the string occupies, whileCHAR_LENGTH()
will return the number of characters.有关
LENGTH()
函数以及所有其他字符串函数的文档可在 此处。Documentation on the
LENGTH()
function, as well as all the other string functions, is available here.查看字符串函数的 MySQL 文档,我们还可以使用 < code>CHAR_LENGTH() 和
CHARACTER_LENGTH()
也是如此。Having a look at MySQL documentation for the string functions, we can also use
CHAR_LENGTH()
andCHARACTER_LENGTH()
as well.我用来求字符串长度的函数是
length
,使用方法如下:The function that I use to find the length of the string is
length
, used as follows:我用这句话来过滤
你可以将 10 更改为你想要过滤的其他数字。
I used this sentences to filter
you can change 10 for other number that you want to filter.
例如,如果您想从客户中选择名称短于 2 个字符的条目。
Example if you want to select from customer the entry's with a name shorter then 2 chars.