简体   繁体   English

MySQL SELECT语句的“长度”字段大于1

[英]MySQL SELECT statement for the “length” of the field is greater than 1

I have an LINK field in my table. 我的桌子上有一个LINK字段。 Some rows have a link, some don't. 有些行有链接,有些则没有。

I'd like to select all rows where LINK is present. 我想选择存在LINK的所有行。 (length is greater than X characters). (长度大于X个字符)。

How do I write this? 我怎么写这个?

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 really interested in how many characters there are, not how many bytes of storage they take. 请注意,我选择了CHAR_LENGTH而不是LENGTH ,就好像数据中有多字节字符,您可能真正感兴趣的是有多少字符,而不是它们占用多少字节。 So for the above, a row where LINK is a single two-byte character wouldn't be returned - whereas it would when using 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. 请注意,如果LINKNULL ,则CHAR_LENGTH(LINK)的结果也将为NULL ,因此该行将不匹配。

select * from [tbl] where [link] is not null and len([link]) > 1

对于MySQL用户:

LENGTH([link]) > 1

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 ;) 以防万一 ;)

Try: 尝试:

SELECT
    *
FROM
    YourTable
WHERE
    CHAR_LENGTH(Link) > x

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM