List:General Discussion« Previous MessageNext Message »
From:mos Date:December 12 2007 11:01pm
Subject:Re: How to count # of occurrences of a char in a string?
View as plain text  
At 04:52 PM 12/12/2007, Baron Schwartz wrote:
>Hi,
>
>On Dec 12, 2007 5:39 PM, mos <mos99@stripped> wrote:
> > I have a Char(50) column and I want to count the number of "." in the
> > column using a Select statement. I don't see any MySQL function that can
> > count the number of occurrences of a character in a string. Is there a
> > simple way to do this?
>
>LENGTH(str) - LENGTH(REPLACE(str, '.', ''))

Baron,

Thanks, I gave it a try and it works. :)

But why can't MySQL create a function to do that otherwise the SQL harder 
is much harder to read.

Just my 2 cents worth.

Mike 
Thread
How to count # of occurrences of a char in a string?mos12 Dec
  • Re: How to count # of occurrences of a char in a string?Baron Schwartz12 Dec
    • Re: How to count # of occurrences of a char in a string?mos13 Dec