PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > mysql.general > How to count # of occurrences of a char in a string?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
How to count # of occurrences of a char in a string?

Réponse
 
LinkBack Outils de la discussion
Vieux 12/12/2007, 22h39   #1
mos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut How to count # of occurrences of a char in a string?

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?

TIA
Mike
  Réponse avec citation
Vieux 12/12/2007, 22h52   #2
Baron Schwartz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to count # of occurrences of a char in a string?

Hi,

On Dec 12, 2007 5:39 PM, mos <mos99@fastmail.fm> 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, '.', ''))
  Réponse avec citation
Vieux 12/12/2007, 23h01   #3
mos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to count # of occurrences of a char in a string?

At 04:52 PM 12/12/2007, Baron Schwartz wrote:
>Hi,
>
>On Dec 12, 2007 5:39 PM, mos <mos99@fastmail.fm> 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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 23h25.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09273 seconds with 11 queries