--測試數據
create table t1(a text)
insert t1 select ‘案發(fā)司法速讀法速讀法司法速讀法速度發(fā)來(lái)了吉林兩歲鳳飛飛速讀法速讀法速讀法‘
--創(chuàng )建查詢(xún)函數
create function f_find(@str varchar(100))
returns int
as begin
declare @a int
declare @b int
declare @c int
declare @d int
declare @e int
declare @str1 varchar(8000)
set @a=0
set @c=0
set @d=1
set @e=1
set @str1=‘‘
while @d<=(select (datalength(a)/3500)+1 from t1) begin
select @str1=substring(a,@e,3500) from t1
set @b=1
while @b>0 begin
select @a=charindex(@str,@str1,@b)
set @b=@a
if @b>0 begin
set @c=@c+1
set @b=@b+1
end
end
set @d=@d+1
set @e=@e+3500
end
return @c
end
--調用
select dbo.f_find(‘發(fā)‘)
/*結果
-----------
2
(所影響的行數為 1 行)
*/
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請
點(diǎn)擊舉報。