问题描述
- 使用sql anywhere创建自定义函数
-
使用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 intset @i = 0
set @e = 0
set @s = 0while @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
解决方案
http://www.cnblogs.com/diony/archive/2010/12/17/1909014.html
时间: 2024-11-07 01:48:53