在SQL Server 2005中使用正则表达式2009-12-27 博客园 ※ABeen※CLR用户定义函数只是在.NET 程序集中定义的静态方法。CREATE FUNCTION 语句已扩展为支持创建 CLR 用户定义函数。1、创建数据库项目

2、添加用户定义函数

以下是演示代码:
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;
}
}