开发者

How to find the string length in a field?

I believe there is a function that I can use to determine the string length but I can't find it on Google. What I want is all rows greater than 255 charac开发者_开发知识库ters. Can someone please shed some light?


Try this:

select *
from table
where length(somefield) > 255;

You have the strange wording that "some row is greater than 255 characters". That might mean

select *
from table
where length(somefield1) + length(somefield2) + length(somefield3) > 255;


You can not find the length of a row (unless that row is made up of only one field). You can find the length of individual fields in a row which have string data in them with length() and char_length().


Sure, length()*, and char_length(). See http://dev.mysql.com/doc...function_length and http://dev.mysql.com/doc...function_char-length

Example:

SELECT  name, email
  FROM  subscribers
  WHERE (char_length(name) > 5)
  LIMIT 1

--

* Returns the length of the string str, measured in bytes. A multi-byte character counts as multiple bytes. This means that for a string containing five two-byte characters, LENGTH() returns 10, whereas CHAR_LENGTH() returns 5.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜