Is there any function in MySQL that looks like the PHP substr_count() function? Actually, I need to know how many elements are in the set (for example, 1,2,3 - 3 elements).
In the search, I did not find anything that would be native to this. So I made a workaround with the LENGTH() and REPLACE() methods.
SELECT LENGTH("1,2,3,4") - LENGTH(REPLACE("1,2,3,4", ",", "")) + 1;
But it is not installed, it is empty.
But I can solve this with a simple IF() .
So, I am looking for another native, for example, for example:
SELECT SUBSTR_COUNT(",", "1,2,3,4") + 1;
Or, even better:
SELECT LENGTH_OF_SET("1,2,3,4");
Are some guys solving?
Edit
Due to some doubt, I will try to give some examples:
1,2,3 has 3 elements: 1, 2 and 3;100,200 has 2 elements: 100 and 200;1,2,4,9,16,25 has 6 elements: 1, 2, 4, 9, 16 and 25;
Basically, I want the number to be the number of commas + 1 . I have this value, but I was wondering if he has his own way of doing this or less expensive than me.