How to count all characters in all rows of a field in MySQL?

I need a character to count the sum of all the characters in a text box in MySQL. I need to know the total number of characters of all messages in this field together and cannot think how I will do it ...

Any help would be great.

Thanks.

+7
source share
3 answers

The number of bytes.,.

select sum(length(your_column_name)) from your_table_name; 

For the number of characters.,.

 select sum(char_length(your_column_name)) from your_table_name; 

The char_length () function supports multibyte characters; five double-byte characters will return as 5.

+22
source

Just sum all the lengths for the field.

 SELECT SUM(CHAR_LENGTH(field)) FROM table 
+4
source

CHAR_LENGH (column) counts with spaces. To count all characters, expect spaces, we must first remove the spaces. Hope this helps.

 SELECT SUM(char_length(REPLACE(column, ' ', ''))) FROM table 
0
source

Source: https://habr.com/ru/post/1380786/


All Articles