Frage

I have a column in a table in MySQL which contains ngrams, and I want to validate that each ngram is of the correct length.

For e.g. if the ngram is 'sophisticated hacking scheme' then the number of blanks should be two.

Is there anything in MySQL that would count the blanks? Or can someone suggest a quick SQL fix?

War es hilfreich?

Lösung

One that I've used in SQL Server, slightly adapted to using MySQL functions is:

CHAR_LENGTH(Column) - CHAR_LENGTH(REPLACE(Column,' ','')

That is - what's the length of the column, vs the length of the column if all of the spaces are removed? That should give you the number of spaces that were present.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top