所以我试图创建我的第一个递归udf(使用MS SQL)去除字符串中不是字母和数字的任何东西。用于删除非字母数字字符的递归SQL UDF
这是由这个帖子的启发(Replace with wildcard, in SQL)
CREATE FUNCTION uf_RemoveNonAlphaNumericChar(
@p_CharIndex int,
@p_Value Varchar(max))
RETURNS varchar(max)
AS
BEGIN
SET @p_CharIndex = PATINDEX('%[^0-9,a-z]%', @p_Value)
SET @p_Value = STUFF(@p_Value,@p_CharIndex , 1, SPace(0))
IF @p_CharIndex > 0
BEGIN
EXEC @p_Value = uf_RemoveNonAlphaNumericChar @p_CharIndex = @p_CharIndex,
@p_Value = @p_Value
END
RETURN @p_Value
END
这在我试图分裂,可能是XXX###YYYY
分为三个部分字符串更大的问题一步,当某些部件可能失踪。
而我试图做一个没有while循环(该解决方案已经存在,但运行缓慢)。
如果Patindex有一个开始位置(在MS SQL中),我已经完成了。当然,这也不会那么有趣。或作为黄铜填充...
FYI'PATINDEX'可以有一个开始postition:'PATINDEX( '%[^ 0-9,AZ]%',SUBSTRING (@p_Value,2,99999))将开始搜索字符串2的字符串 – JNK