gpt4 book ai didi

mysql - MySQL如何知道一个段落包含多少个单词?

转载 作者:行者123 更新时间:2023-11-29 05:00:16 25 4
gpt4 key购买 nike

我可以使用哪些 MySQL 函数?

例如,

What Mysql function can I use?

包含 6 个单词。

最佳答案

我不知道是否有内置函数,但我在 MySQL 的 String Functions 的注释中找到了这个文档:


我在 mysql 中寻找 word_count("string"),最后想出了一个用户定义的函数,这对我来说非常有用,注意:我使用的是实际空间。

DROP FUNCTION IF EXISTS word_count;
CREATE FUNCTION word_count (f_string text(5000)) RETURNS smallint(10)
BEGIN
DECLARE new_string text(5000);
WHILE INSTR(f_string,'<space><space>')>0
DO
SET new_string=(select REPLACE(f_string,'<space><space>','<space>'));
SET f_string=new_string;
END WHILE;

RETURN (select LENGTH(TRIM(f_string))-LENGTH(REPLACE(TRIM(f_string),'<space>',''))+1);
END
//

这是结果

mysql> select word_count("Balaji Devarajan") WORD_COUNT;

+------------+
| WORD_COUNT |
+------------+
| 2 |
+------------+
1 row in set (0.00 sec)

mysql> select word_count(" Balaji Devarajan ") WORD_COUNT;

+------------+
| WORD_COUNT |
+------------+
| 2 |
+------------+
1 row in set (0.00 sec)

mysql> select word_count("Balaji Devarajan") WORD_COUNT;

+------------+
| WORD_COUNT |
+------------+
| 2 |
+------------+
1 row in set (0.01 sec)

关于mysql - MySQL如何知道一个段落包含多少个单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1781033/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com