Here We will figure out how to calculate count of occurence of a character in a string or count the number of occurrences of a string in a VARCHAR field.
Lets explain with example
Case 1 : calculate how many time '-' is used in the string ABC-CD-EF-10101.
SET @item='ABC-CD-EF-10101';
SELECT ROUND(
(
LENGTH(@item)
- LENGTH( REPLACE (@item,"-", "") )
)
) as Count;
Output : 3