【问题标题】:Allowing users to specify regular expressions in SQL select statement in T-SQL允许用户在 T-SQL 中的 SQL select 语句中指定正则表达式
【发布时间】:2012-02-18 08:48:01
【问题描述】:

我需要你的建议。我正在编写一个 ASP.NET Web 应用程序,并且正在考虑是否允许用户使用正则表达式在数据库中指定搜索词。

两个问题:

  1. SQL Server 是否支持对 SELECT 语句使用正则表达式?

  2. 允许用户为数据库选择指定正则表达式是否安全?

【问题讨论】:

    标签: sql regex sql-server-2005 tsql select


    【解决方案1】:
    • 1 - 否,但您可以为此使用 CLR 函数,例如:

      public partial class UserDefinedFunctions
      {
          [Microsoft.SqlServer.Server.SqlFunction(DataAccess = DataAccessKind.None, IsDeterministic = true)]
          public static SqlBoolean RegexMatch(string Pattern, string Expression)
          {
              return new Regex(Pattern).IsMatch(Expression);
          }
      };
      
    • 2 - 安全完全取决于您的认识

    【讨论】:

      猜你喜欢
      • 2016-10-10
      • 1970-01-01
      • 2011-08-21
      • 2010-09-16
      • 2015-12-26
      • 2022-12-17
      • 2016-03-07
      • 2011-03-16
      相关资源
      最近更新 更多