select id,length(string)-length(replace(string,',','')) cnt from strings
length()查看字符串的长度
- 计算单位:字节
- utf8编码:一个汉字三个字节,一个数字或字母一个字节。
- gbk编码:一个汉字两个字节,一个数字或字母一个字节。
用replace 将‘,’替换为空值 则减少的长度即为‘,’的次数
select id,length(string)-length(replace(string,',','')) cnt from strings
length()查看字符串的长度
用replace 将‘,’替换为空值 则减少的长度即为‘,’的次数