WEB开发网
开发学院数据库MySQL SQL中自己创建函数,分割字符串 阅读

SQL中自己创建函数,分割字符串

 2008-10-20 11:11:39 来源:WEB开发网   
核心提示: WHILE @temp_i<@iBEGINselect @onlineornot = online from wwchat_user where epnum=dbo.getstrofindex(@str,',',@temp_i)IF (@onlineornot=1)b

WHILE @temp_i<@i

BEGIN

select @onlineornot = online from wwchat_user where epnum=dbo.getstrofindex(@str,',',@temp_i)      

IF (@onlineornot=1)

begin

select @str_return =dbo.getstrofindex(@str,',',@temp_i)

select @findepnumok = 1 --找到epnum后置为1

BREAK

end

ELSE

begin

select @temp_i = @temp_i + 1

select @findepnumok = 0 --找不到epnum后置为1

end

END

if @findepnumok = 0

begin

SELECT @str_return = '00000000'

end

end

return @str_return 

end

GO

SET QUOTED_IDENTIFIER OFF

GO

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

SET ANSI_NULLS ON

GO

--getstrcount 输入一个没有分割的字符串,以及分割符

--返回数组的个数

CREATE   function getstrcount (@str varchar(8000),@splitstr varchar(100)) 

--returns varchar(8000) 

returns int

as 

begin 

declare @int_return int 

declare @start int 

declare @next int

declare @location int 

select @next = 0

select @location = 1

if len(@str)<len(@splitstr)

select @int_return =0

if charindex(@splitstr,@str) = 0

select @int_return =0

while (@location<>0) 

begin 

select @start = @location + 1 

Tags:SQL 自己 创建

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接