用replace替换字符为空,然后计算前后字符串长度之差就行,不用想太复杂

select id,
    length(string)-length(replace(string,',',''))
from strings