Afficher un message
Vieux 04/09/2007, 16h55   #5
Francesco Riosa
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: finding count of spaces in a string

dpgirago@mdanderson.org ha scritto:
> We have numerous identical tables with a varchar column that holds data
> like this: "0 0 0 1 0 1 0 25 7 0 139 0 9". Essentially there are a bunch
> of integers with a single space as a separator. There _should_ be no more
> than 30 entries ( and 29 spaces ), but sometimes the system misfires and
> there are more or less. Is there a MySQL solution to getting a count of
> the spaces present in the field, figuring that spaces + 1 will equal
> entries? It's fairly straight forward using a PHP application, but I'd
> like to get the DB server to accomplish this task. Not having much luck
> finding a solution in the manual.
>
>


SELECT 1
+ CHAR_LENGTH("0 0 0 1 0 1 0 25 7 0 139 0 9")
- CHAR_LENGTH(REPLACE("0 0 0 1 0 1 0 25 7 0 139 0 9", " ", ""))
AS ret


HopeIt,
Francesco

  Réponse avec citation
 
Page generated in 0,05036 seconds with 9 queries