加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

microsoft sql相当于mysql的REGEXP

发布时间:2020-12-14 04:27:30 所属栏目:Windows 来源:网络整理
导读:我正在尝试重建我在Microsoft sql中为 mysql创建的数据库查询.我在Microsoft sql中寻找一个术语,其行为类似于REGEXP 这是一个如何使用该术语的例子 select * from musicdetails WHERE artistname REGEXP '^".mysql_escape_string($_GET['search'])."$' 任何
我正在尝试重建我在Microsoft sql中为 mysql创建的数据库查询.我在Microsoft sql中寻找一个术语,其行为类似于REGEXP

这是一个如何使用该术语的例子

select * from musicdetails WHERE artistname REGEXP '^".mysql_escape_string($_GET['search'])."$'

任何帮助将非常感激

解决方法

在这里(编译为SQL CLR程序集):

using System.Collections;
using System.Text.RegularExpressions;
using Microsoft.SqlServer.Server;

public partial class UserDefinedFunctions
{
  [SqlFunction]
  public static bool RegexMatch(string expr,string regex)
  {
    return Regex.IsMatch(expr,regex);
  }

  [SqlFunction]
  public static string RegexReplace(string expr,string regex,string replace)
  {
    return Regex.Replace(expr,regex,replace);
  }

  [SqlFunction(FillRowMethodName="GetToken",TableDefinition="Value nvarchar(max)")]
  public static IEnumerable RegexSplit(string expr,string regex)
  {
    return Regex.Split(expr,regex);
  }

  public static void GetToken(object row,out string str)
  {
     str = (string) row;
  }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读