MySQL SELECT 语句用于字段的“长度”大于 1
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1545467/
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
MySQL SELECT statement for the "length" of the field is greater than 1
提问by TIMEX
I have an LINK field in my table. Some rows have a link, some don't.
我的表中有一个 LINK 字段。有些行有链接,有些没有。
I'd like to select all rows where LINK is present. (length is greater than X characters).
我想选择存在 LINK 的所有行。(长度大于 X 个字符)。
How do I write this?
我该怎么写?
回答by Jon Skeet
How about:
怎么样:
SELECT * FROM sometable WHERE CHAR_LENGTH(LINK) > 1
Here's the MySql string functions page(5.0).
这是MySql 字符串函数页面(5.0)。
Note that I chose CHAR_LENGTH
instead of LENGTH
, as if there are multibyte characters in the data you're probably reallyinterested in how many characters there are, not how many bytes of storage they take. So for the above, a row where LINK is a single two-byte character wouldn't be returned - whereas it would when using LENGTH
.
请注意,我选择了CHAR_LENGTH
而不是LENGTH
,好像数据中有多字节字符一样,您可能真正感兴趣的是有多少字符,而不是它们占用多少字节的存储空间。因此,对于上述情况,不会返回 LINK 是单个两字节字符的行 - 而使用LENGTH
.
Note that if LINK
is NULL
, the result of CHAR_LENGTH(LINK)
will be NULL
as well, so the row won't match.
注意,如果LINK
是NULL
,结果CHAR_LENGTH(LINK)
将是NULL
一样,所以该行不匹配。
回答by Amy
select * from [tbl] where [link] is not null and len([link]) > 1
For MySQL user:
对于 MySQL 用户:
LENGTH([link]) > 1
回答by alizelzele
Just in case anybody want to find how in oracle and came here (like me), the syntax is
以防万一有人想在 oracle 中找到方法并来到这里(像我一样),语法是
select length(FIELD) from TABLE
just in case ;)
以防万一 ;)
回答by KM.
Try:
尝试:
SELECT
*
FROM
YourTable
WHERE
CHAR_LENGTH(Link) > x