qq_20497589
qq_20497589
采纳率0%
2016-03-07 02:25 阅读 1.5k

使用sql anywhere创建自定义函数

5

使用sql anywhere创建自定义函数:GetSegStr(源串,分隔串,序号),返回字符串
功能:获取指定序号的按分隔串分隔的源串,
举例:
GetSegStr('abc-def-gh', '-', 1) = abc
GetSegStr('abc-def-gh', '-', 2) = def
GetSegStr('abc-def-gh', '-', 3) = gh

下面是SQL代码 帮忙改成SQL anywhere 谢谢

create function GetSegStr ( @source varchar(1000),@div varchar(10),@char_idx int )
returns varchar(1000)
as
begin
declare @c varchar(1000)
declare @i int
declare @i_p int
declare @s int
declare @e int

set @i = 0
set @e = 0
set @s = 0

while @i < @char_idx and charindex(@div,@source,@s + 1) > 0
begin
set @s = @e
set @e = charindex(@div,@source,@s + 1)
set @i = @i + 1
end
if @e = 0
set @e = LEN(@source) + 1
return substring(@source,@s + 1,@e - @s - 1 )
end

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新