楼主: sabin
8434 12

如何在字符串中查找重复子字符串的位置? [推广有奖]

11
soporaeternus 发表于 2013-12-19 09:36:17
按bobguy的方法做依次做个0-1字符串连接或是2进制累加就可以了
Let them be hard, but never unjust

12
sabin 发表于 2013-12-20 17:03:59
zw612003 发表于 2013-12-19 00:05
求教SQL高级写法。
SQL中没有现成的函数,我自己写了一个

create function stringTimes(@string1 varchar(100),@string2 varchar(100))
returns int
as
begin
declare @len1 int,@len2 int,@index int,@times int
set @len1=len(@string1)
set @len2=len(@string2)
set @index=1
set @times=0
while @index<=@len1-@len2+1
begin
if(substring(@string1,@index,@len2)=@string2)
begin
set @times=@times+1
set @index=@index+1
end
else
set @index=@index+1
continue
end
return @times
end
go  
  
已有 1 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
Tigflanker + 5 + 3 + 3 + 3 观点有启发

总评分: 论坛币 + 5  学术水平 + 3  热心指数 + 3  信用等级 + 3   查看全部评分

13
天堂之路 发表于 2014-1-4 17:36:19
看看

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-30 15:43