标签:not function 返回值 tmp 分享 returns .com abc tin
摘要:例:
实现原理:判断 是否包含特殊字符,是否全部为0-9的自然数组成
CREATE FUNCTION dbo.check_number
(
/*验证一字符串类型是否为整型数值类型*/
@checkTmp VARCHAR(100)
)
RETURNS BIT
BEGIN
DECLARE @tmp BIT
IF LEFT(@checkTmp, 1) = ‘-‘
SET @checkTmp = SUBSTRING(@checkTmp, 2, LEN(@checkTmp))
IF (PATINDEX(‘%[^0-9-]%‘, @checkTmp) = 0
AND CHARINDEX(‘-‘, @checkTmp) <= 1
AND @checkTmp NOT IN (‘.‘, ‘-‘, ‘+‘, ‘^‘)
AND LEN(@checkTmp)>0
AND @checkTmp NOT LIKE ‘%-%‘)
SET @tmp = 1
ELSE
SET @tmp = 0
RETURN @tmp
END
GO
/*数据验证*/
SELECT ‘878‘ [测试数值],dbo.check_number(‘999‘) [测试返回值];
SELECT ‘testData‘ [测试数值],dbo.check_number(‘abc‘) [测试返回值];
SELECT ‘8-8‘ [测试数值],dbo.check_number(‘9+9‘) [测试返回值];
SELECT ‘8.9‘ [测试数值],dbo.check_number(‘$9.9‘) [测试返回值];
SELECT ‘maomao365.com‘ [测试数值],dbo.check_number(‘maomao365.com‘) [测试返回值];
go
drop function check_number
标签:not function 返回值 tmp 分享 returns .com abc tin
原文地址:http://blog.51cto.com/13806592/2129745