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
  • 相关阅读:
    kvm虚拟机网络管理
    kvm虚拟机存储管理
    kvm虚拟机迁移
    KVM嵌套虚拟化nested之CPU透传
    kvm认识和安装
    博客美化(二)
    日志管理
    IP分为五类
    windows(xshell)免密码登录
    mpvue的toast弹窗组件-mptosat
  • 原文地址:https://www.cnblogs.com/zldqpm/p/12028471.html
Copyright © 2011-2022 走看看