zoukankan      html  css  js  c++  java
  • Sql Server 使用正则表达式

     

    create function dbo.RegexMatch (    
     
    @pattern varchar(2000),    
     
    @matchstring varchar(8000)
     
    )
     
    returns int
     
    as
     
    begin   
     
        declare @objRegexExp int   
     
        declare @strErrorMessage varchar(255)    
     
        declare @hr int,@match bit   
     
        exec @hr= sp_OACreate 'VBScript.RegExp', @objRegexExp out   
     
        if @hr = 0        
     
            exec @hr= sp_OASetProperty @objRegexExp, 'Pattern', @pattern    
     
        if @hr = 0        
     
            exec @hr= sp_OASetProperty @objRegexExp, 'IgnoreCase', 1    
     
        if @hr = 0        
     
            exec @hr= sp_OAMethod @objRegexExp, 'Test', @match OUT, @matchstring    
     
        if @hr <>0    
     
        begin       
     
            return null   
     
        end   
     
        exec sp_OADestroy @objRegexExp    
     
        return @match
     
    end

    调用

    SELECT * FROM table where dbo.RegexMatch('正则表达式',字段名)=0

    如果执行报错 执行这个语句

    --开启 Ole Automation Procedures
    sp_configure 'show advanced options', 1;
    GO
    RECONFIGURE;
    GO
    sp_configure 'Ole Automation Procedures', 1;
    GO
    RECONFIGURE;
    GO
    EXEC sp_configure 'Ole Automation Procedures';
    GO
    
    --关闭 Ole Automation Procedures
    sp_configure 'show advanced options', 1;
    GO
    RECONFIGURE;
    GO
    sp_configure 'Ole Automation Procedures', 1;
    GO
    RECONFIGURE;
    GO
    EXEC sp_configure 'Ole Automation Procedures';
    GO
    
    --关闭高级选项
    sp_configure 'show advanced options', 0;
    GO
    RECONFIGURE;
    GO
  • 相关阅读:
    Linux下使用mtr做路由图进行网络分析
    PHP使用AJAX返回登录成功信息完整参考代码
    ajax提交表单数据不跳转
    帝国cms常用变量总结
    2020软件工程作业04
    2020软件工程作业03
    疑问
    2020软件工程02
    疑问
    2020软件工程作业01
  • 原文地址:https://www.cnblogs.com/zldqpm/p/12028471.html
Copyright © 2011-2022 走看看