Step 4 : The difference between previous calculation ( Step 1 ) and present calculation ( Step 3 ) is the number of ‘/’ present in the string. WE will combine all into one query .
To get the number of occurrence of a search string ,we have used the difference between length of the string before removing the search string and after removing the search string.
Searching for a word of more than one character length.
Directly we can’t apply the above technique to find out number of occurrence of a search string of more than one character length. We need to divide the difference with the length of the search string to get the number of occurrences of the search sting.
We will search for the string 'sql' inside another main string.
We will collect names from our student table where our search string 'John' is present.
SELECT * FROM `student` WHERE
(
CHARACTER_LENGTH(name) -
CHARACTER_LENGTH(REPLACE(name,'John',''))
) / CHARACTER_LENGTH('John') >0
We will get a list of names with 'John' inside them.
This is only an example to show how to count number of occurrence of a string and this is not a better way to filter records based on matching conditions. To get records with condition better to use LIKE query