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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 16:27:06  来源:igfitidea点击:

How to select one text column, which string length >0?

mysql

提问by lovespring

Is there any function like "strlen" in mysql?

mysql中有没有像“strlen”这样的函数?

回答by Robby Pond

Mysql does have a lengthfunction to return the length of a string.

Mysql 确实有一个length函数来返回字符串的长度。

so you could do something like.

所以你可以做类似的事情。

select * from some_table where length(some_string) > 0;

回答by onurbaysan

You can do it with using LENGTHkeyword

您可以使用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() 将返回字符数

MySQL - How to select data by string length

MySQL - 如何按字符串长度选择数据