문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top