使用SQL搜索字符串中的单词数 [英] Search count of words within a string using SQL
本文介绍了使用SQL搜索字符串中的单词数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
数据库:Sql Server
我有一个名为page_text的表列,其中包含以下值
I Love stackoverflow.com,因为我可以随时提出问题并获得
的答案。
使用 SQLQUERY 我要搜索 I
的数量。因此在这个字符串中它应该返回4.
我应该能够搜索任何东西。
解决方法 $
declare @search varchar(10)='I'
select len(PageText,@search,@search + #'))
- len(PageText)as Count from YourTable
Database: Sql Server
I have table column named page_text which contains following value
" I Love stackoverflow.com because i can post questions and get answers at any time. "
Using SQLQUERY i want to search the number of I
it has . So in this string it would should return 4.
I should be able to search anything.
解决方案
declare @search varchar(10) = 'I'
select len(replace(PageText, @search, @search + '#'))
- len(PageText) as Count from YourTable
这篇关于使用SQL搜索字符串中的单词数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文