Code using System; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; using Microsoft.SqlServer.Server; using System.Text.RegularExpressions; // 示意代码 public partial class UserDefinedFunctions { public static readonly RegexOptions Options = RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline; [Microsoft.SqlServer.Server.SqlFunction] public static string RegexValue(SqlChars input, SqlString pattern) { Regex regex = new Regex(pattern.Value, Options); return regex.Match(new string(input.Value)).Value; } } |
EXEC sp_configure 'clr enabled', 1 sql 如下: select dbo.RegexValue('2008-09-02',N'\d{4}') from Table ============================================= |