Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query to count words SQLite 3

Is there a way to count words in a text string?

I'm using SQLite 3 and I'm trying to write a query that takes a bunch of long strings of text, and counts the number of words in each one.

I also want to ignore html tags (or anything between carets) such as paragraph tags, break tags, etc.

So when I run a query selecting text from the appropriate column, I get a large wordy text output with some html tags in it, and I just want to count the words.

How can I write a query to do this?

like image 411
user396247 Avatar asked Jul 20 '10 19:07

user396247


1 Answers

As far as I know there is no way to directly count the number of words in a string in SQL lite 3. (I'm more familiar with mysql and ms sql)

You can use Length and Replace as a work around

 SELECT length(@String) - length(replace(@String, ' ', '')) + 1
like image 164
b8b8j Avatar answered Sep 30 '22 22:09

b8b8j