SQL Server 检测字符串中是否有重复字符的函数

来源:这里教程网 时间:2026-03-02 10:00:22 作者:

SQL Server 2000

检测字符串中是否有重复字符的函数

Create Function FN_DupChar
(@String Varchar(100))
Returns Bit
As
Begin
Declare @Temp Table(Chr Varchar(1))

Declare @i Int ,@j Int
Select @i = 1, @j = 0
While @i <= Len(@String)
Begin
Insert Into @Temp Select Substring(@String,@i,1)
Select @i = @i + 1
End

If Exists(Select 1 From @Temp Group By Chr Having Count(*) > 1)
Begin
Set @j = 1
End
Return @j

End

[@more@]

相关推荐