例如 set t="11,4,19,32" 如何能得到t=4的结果啊,或者得到","这个字符在t里出现的次数也行。

解决方案 »

  1.   

    SELECT LENGTH(T)-LENGTH(REPLACE(T,',',''))+1
      

  2.   

    对,做一下替换处理,然后比较一下字符串长度减少的数量。select length(t)-length(replace(t,',',''))+1
      

  3.   

    mysql> set @t="11,4,19,32";
    Query OK, 0 rows affected (0.44 sec)mysql> select length(@t)-length(replace(@t,',',''))+1;
    +-----------------------------------------+
    | length(@t)-length(replace(@t,',',''))+1 |
    +-----------------------------------------+
    |                                       4 |
    +-----------------------------------------+
    1 row in set (0.19 sec)mysql>
      

  4.   

    用length的话是否需要再除以length(','),当然要是全英文的话就没有必要多此一举了
    用char_length会靠谱一点
    SELECT ( char_length( 'test' ) - char_length( replace('test', 't' , '')))