How to count the number of occurrences of a character in a string in MySQL SQL statement

A student asked me, Mr. Jin: How many "0" sub-characters in a string like "0, 1, 2, 3, 0, 2" can be realized in MySQL

Implementation: first calculate the length of the string, then delete all "0"s in the string, calculate
the length
of the string after deleting the "0" , the difference between the two lengths is the character "0" appears in the string The number of times .
MYSQL, Oracle, DB2:

 select password,length(password)-length(replace(password,'0','')) from linshi;

WeChat image_20210127121429.png

Ok, that's it for today


Guess you like

Origin blog.51cto.com/jinyan2049/2607925