sql 判断字段中是否含有字符
1个回答
展开全部
1. 查询字符串中是否包含非数字字符
SELECT PATINDEX('%[^0-9]%', '1235X461')
SELECT PATINDEX('%[^0-9]%', '12350461')
2. 查询字符串中是否包含数字字符
SELECT PATINDEX('%[0-9]%', 'SUYLLGoO')
SELECT PATINDEX('%[0-9]%', 'SUYLLG0O')
3.函数判断字符串只包含数字
CREATE FUNCTION [dbo].fn_IsNumeric
(
@pString VARCHAR(8000)
)
RETURNS bit
WITH ENCRYPTION
AS
BEGIN
DECLARE @vJudge int
SET @vJudge = 0
SELECT @vJudge =
CASE
WHEN PATINDEX('%[0-9]%', LOWER(@pString)) > 0 THEN 0
WHEN PATINDEX('%[0-9]%', LOWER(@pString)) = 0 THEN 1
END
RETURN @vJudge
END
4.函数判断字符串只包含字母(忽略大小写)
CREATE FUNCTION [dbo].fn_IsAlpha
(
@pString VARCHAR(8000)
)
RETURNS bit
WITH ENCRYPTION
AS
BEGIN
DECLARE @vJudge int
SET @vJudge = 0
SELECT @vJudge =
CASE
WHEN PATINDEX('%[a-z]%', LOWER(@pString)) > 0 THEN 0
WHEN PATINDEX('%[a-z]%', LOWER(@pString)) = 0 THEN 1
END
RETURN @vJudge
END
5. 函数判断字符串不包含任何符号(包括空格)
CREATE FUNCTION [dbo].fn_IsAlphanumeric
(
@pString VARCHAR(8000)
)
RETURNS bit
WITH ENCRYPTION
AS
BEGIN
DECLARE @vJudge int
SET @vJudge = 0
SELECT @vJudge =
CASE
WHEN PATINDEX('%[^a-z0-9]%', LOWER(@pString)) > 0 THEN 0
WHEN PATINDEX('%[^a-z0-9]%', LOWER(@pString)) = 0 THEN 1
END
RETURN @vJudge
END
6. 函数判断字符串不包含任何符号(除空格外)
CREATE FUNCTION [dbo].fn_IsAlphanumericBlank
(
@pString VARCHAR(8000)
)
RETURNS bit
WITH ENCRYPTION
AS
BEGIN
DECLARE @vJudge int
SET @vJudge = 0
SELECT @vJudge =
CASE
WHEN PATINDEX('%[^a-z0-9 ]%', LOWER(@pString)) > 0 THEN 0
WHEN PATINDEX('%[^a-z0-9 ]%', LOWER(@pString)) = 0 THEN 1
END
RETURN @vJudge
END
SELECT PATINDEX('%[^0-9]%', '1235X461')
SELECT PATINDEX('%[^0-9]%', '12350461')
2. 查询字符串中是否包含数字字符
SELECT PATINDEX('%[0-9]%', 'SUYLLGoO')
SELECT PATINDEX('%[0-9]%', 'SUYLLG0O')
3.函数判断字符串只包含数字
CREATE FUNCTION [dbo].fn_IsNumeric
(
@pString VARCHAR(8000)
)
RETURNS bit
WITH ENCRYPTION
AS
BEGIN
DECLARE @vJudge int
SET @vJudge = 0
SELECT @vJudge =
CASE
WHEN PATINDEX('%[0-9]%', LOWER(@pString)) > 0 THEN 0
WHEN PATINDEX('%[0-9]%', LOWER(@pString)) = 0 THEN 1
END
RETURN @vJudge
END
4.函数判断字符串只包含字母(忽略大小写)
CREATE FUNCTION [dbo].fn_IsAlpha
(
@pString VARCHAR(8000)
)
RETURNS bit
WITH ENCRYPTION
AS
BEGIN
DECLARE @vJudge int
SET @vJudge = 0
SELECT @vJudge =
CASE
WHEN PATINDEX('%[a-z]%', LOWER(@pString)) > 0 THEN 0
WHEN PATINDEX('%[a-z]%', LOWER(@pString)) = 0 THEN 1
END
RETURN @vJudge
END
5. 函数判断字符串不包含任何符号(包括空格)
CREATE FUNCTION [dbo].fn_IsAlphanumeric
(
@pString VARCHAR(8000)
)
RETURNS bit
WITH ENCRYPTION
AS
BEGIN
DECLARE @vJudge int
SET @vJudge = 0
SELECT @vJudge =
CASE
WHEN PATINDEX('%[^a-z0-9]%', LOWER(@pString)) > 0 THEN 0
WHEN PATINDEX('%[^a-z0-9]%', LOWER(@pString)) = 0 THEN 1
END
RETURN @vJudge
END
6. 函数判断字符串不包含任何符号(除空格外)
CREATE FUNCTION [dbo].fn_IsAlphanumericBlank
(
@pString VARCHAR(8000)
)
RETURNS bit
WITH ENCRYPTION
AS
BEGIN
DECLARE @vJudge int
SET @vJudge = 0
SELECT @vJudge =
CASE
WHEN PATINDEX('%[^a-z0-9 ]%', LOWER(@pString)) > 0 THEN 0
WHEN PATINDEX('%[^a-z0-9 ]%', LOWER(@pString)) = 0 THEN 1
END
RETURN @vJudge
END
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询