• 标量值函数—— 判断是否存在特殊字符


    Create    FUNCTION [dbo].[IsOnlyNumAndEngth] --只允许数字,字幕和一个额外的特殊字符
        (
          @str VARCHAR(8000),
          @escape1 CHAR = '' --额外的特殊字符
        )
    RETURNS BIT
    AS 
        BEGIN 
            DECLARE @i INT 
            DECLARE @j INT 
            DECLARE @k BIT 
            DECLARE @g CHAR
            SET @i = DATALENGTH(@str) 
            SET @j = 1 
            SET @k = 1 
            IF @str = '' 
                BEGIN
                    SET @k = 0 
                END
            WHILE @j <= @i 
                BEGIN 
                    SET @g = SUBSTRING(@str, @j, 1)
                    IF ( ASCII(@g) NOT IN ( ASCII('1'), ASCII('2'), ASCII('3'),
                                            ASCII('4'), ASCII('5'), ASCII('6'),
                                            ASCII('7'), ASCII('8'), ASCII('9'),
                                            ASCII('0'), ASCII('Q'), ASCII('W'),
                                            ASCII('E'), ASCII('R'), ASCII('T'),
                                            ASCII('Y'), ASCII('U'), ASCII('I'),
                                            ASCII('O'), ASCII('P'), ASCII('A'),
                                            ASCII('S'), ASCII('D'), ASCII('F'),
                                            ASCII('G'), ASCII('H'), ASCII('J'),
                                            ASCII('K'), ASCII('L'), ASCII('Z'),
                                            ASCII('X'), ASCII('C'), ASCII('V'),
                                            ASCII('B'), ASCII('N'), ASCII('M'),
                                            ASCII('q'), ASCII('w'), ASCII('e'),
                                            ASCII('r'), ASCII('t'), ASCII('y'),
                                            ASCII('u'), ASCII('i'), ASCII('o'),
                                            ASCII('p'), ASCII('a'), ASCII('s'),
                                            ASCII('d'), ASCII('f'), ASCII('g'),
                                            ASCII('h'), ASCII('j'), ASCII('k'),
                                            ASCII('l'), ASCII('z'), ASCII('x'),
                                            ASCII('c'), ASCII('v'), ASCII('b'),
                                            ASCII('n'), ASCII('m'),
                                            ASCII(@escape1) ) ) 
                        BEGIN 
                            SET @k = 0 
                            BREAK 
                        END
                    SET @j = @j + 1 
                END 
            RETURN   @k 
        END
    勤劳一日,便得一夜安眠;勤劳一生,便得幸福长眠。
  • 相关阅读:
    Linix的mysql操作
    Linix安装Mongo
    什么是GitHub
    PHP date, strtotime, mktime处理
    正则表达式及使用
    JavaScript的算法和流程控制总结
    JavaScript的DOM编程总结
    Yii中使用的简单方法
    Mongo数据库的导入导出及使用
    linux-0.11内核 任务的堆栈切换
  • 原文地址:https://www.cnblogs.com/zhaomengmeng/p/6076877.html
Copyright © 2020-2023  润新知