USE [master]
GO
/****** Object: UserDefinedFunction [dbo].[CharRepeat] Script Date: 04/06/2016 17:32:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- 返回字符串中某字符出现次数,返回结果为INT,@str 字符串 @sub 目标字符,源码来源于百度搜索
-- =============================================
ALTER function [dbo].[CharRepeat](@str varchar(8000),@sub varchar(50))
returns int
as
begin
declare @pos int,@n int
select @n=0, @pos=charindex(@sub,@str)
while(@pos<>0)
begin
select @str=right(@str,len(@str)-@pos),@pos=charindex(@sub,@str),@n=@n+1
end
return(@n)
end
时间: 2024-10-06 07:06:49