首页 > sql server > tsql 从内容中获取电话号码
2016七月29

tsql 从内容中获取电话号码

enjoyasp.net sql server 评论关闭

/*
 * 从内容中获取电话号码
 */
--SELECT dbo.GeTelFromContent('已订18620023427/4')
ALTER function [dbo].[GeTelFromContent](@str VARCHAR(MAX))
RETURNS VARCHAR(50)
AS
BEGIN
	DECLARE @validchars VARCHAR(100) = '[1][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
	DECLARE @idx INT,@Result VARCHAR(50)

	SET @idx = PATINDEX('%'+ @validchars +'%',@str)
	--SELECT @idx
	IF @idx > 0 AND ( @idx = LEN(@str)-10 OR PATINDEX(SUBSTRING(@str,@idx+11,1),'[0-9]')=0 )
	BEGIN
		SET @Result=SUBSTRING(@str ,PATINDEX('%'+ @validchars +'%',@str), 11)
	END
	ELSE
	BEGIN
		SET @Result = ''
	END

	RETURN @Result

END	

本文地址:http://enjoyasp.net/?p=3244 , 转载请保留.

本文的评论功能被关闭了.