通过2个函数CHARINDEX和PATINDEX以及通配符的灵活使用,判断字符串中包含子字符串的方法 无 源码与演示: 源码出处 1. 查询字符串中是否包含非数字字符SELECT PATINDEX(‘%[^0-9本文来源gaodaimacom搞#^代%!码&网(]%’, ‘1235X461’)SELECT PATINDEX(‘%[^0-9]%’, ‘12350461’)2. 查询字符串中是否包
通过2个函数 CHARINDEX 和 PATINDEX 以及通配符的灵活使用,判断字符串中包含子字符串的方法
源码与演示:源码出处
<style> .CodeEntity .code_pieces ul.piece_anchor{width:25px;position:absolute;top:25px;left:-30px;z-index:1000;} .CodeEntity .code_pieces ul.piece_anchor li{width:25px;background: #efe;margin-bottom:2px;} .CodeEntity .code_pieces ul.piece_anchor li{border-left:3px #40AA63 solid;border-right:3px #efe solid;} .CodeEntity .code_pieces ul.piece_anchor li:hover{border-right:3px #40AA63 solid;border-left:3px #efe solid;} .CodeEntity .code_pieces ul.piece_anchor li a{color: #333;padding: 3px 10px;} .CodeEntity .code_pieces .jump_to_code{visibility:hidden;position:relative;} .CodeEntity .code_pieces .code_piece:hover .jump_to_code{visibility:visible;} .CodeEntity .code_pieces .code_piece:hover .jump_to_code a{text-decoration:none;} .CodeEntity .code_pieces h2 i{float:right;font-style:normal;font-weight:normal;} .CodeEntity .code_pieces h2 i a{font-size:9pt;background: #FFFFFF;color:#00A;padding: 2px 5px;text-decoration:none;} </style> <!—ecms
- –> <!—ecms
- $velocityCount
–> <!—ecms
–>
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 bitWITH ENCRYPTIONASBEGINDECLARE @vJudge intSET @vJudge = 0SELECT @vJudge =CASEWHEN PATINDEX('%[0-9]%', LOWER(@pString)) > 0 THEN 0WHEN PATINDEX('%[0-9]%', LOWER(@pString)) = 0 THEN 1ENDRETURN @vJudgeEND4.函数判断字符串只包含字母(忽略大小写)CREATE FUNCTION [dbo].fn_IsAlpha(@pString VARCHAR(8000))RETURNS bitWITH ENCRYPTIONASBEGINDECLARE @vJudge intSET @vJudge = 0SELECT @vJudge =CASEWHEN PATINDEX('%[a-z]%', LOWER(@pString)) > 0 THEN 0WHEN PATINDEX('%[a-z]%', LOWER(@pString)) = 0 THEN 1ENDRETURN @vJudgeEND