MySQL 如何选择一个文本列,哪个字符串长度> 0?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3157643/
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
How to select one text column, which string length >0?
提问by lovespring
Is there any function like "strlen" in mysql?
mysql中有没有像“strlen”这样的函数?
回答by Robby Pond
回答by onurbaysan
You can do it with using LENGTH
keyword
您可以使用LENGTH
关键字来做到这一点
SELECT * FROM table WHERE LENGTH (name) > 150;
回答by Mark Byers
How to select one text column, which string length >0 ?
如何选择一个文本列,其中字符串长度 >0 ?
You could compare to the empty string:
您可以与空字符串进行比较:
SELECT yourcolumn
FROM yourtable
WHERE yourcolumn <> ''
回答by bragboy
The following query would do the job for you.
以下查询将为您完成这项工作。
select length(your_text_column) from sample_table where length(some_column) > 0
回答by Jason
For anyone who comes across this answer in Google, keep this in mind:
对于在 Google 中遇到此答案的任何人,请记住这一点:
Actually, CHAR_LENGTH() should be a better choice. For multi-byte charsets LENGTH() will give you the number of bytes the string occupies, while CHAR_LENGTH() will return the number of characters
实际上,CHAR_LENGTH() 应该是更好的选择。对于多字节字符集,LENGTH() 将为您提供字符串占用的字节数,而 CHAR_LENGTH() 将返回字符数