国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > SQL Server > 正文

T-SQL中使用正則表達式函數

2024-08-31 00:58:41
字體:
來源:轉載
供稿:網友
首先,我們在VSTS中創建一Database Project,增一個class, 實現下面的一個方法:

復制代碼 代碼如下:


/// <summary>
/// Regs the ex match.
/// </summary>
/// <param>The input value.</param>
/// <param>The regex pattern.</param>
/// <remarks>Author: Petter Liu </remarks>
/// <returns>1 match,0 not match</returns>
[SqlFunction]
public static bool RegExMatch(string inputValue, string regexPattern)
{
// Any nulls - we can't match, return false
if (string.IsNullOrEmpty(inputValue) || string.IsNullOrEmpty(regexPattern))
return false;

Regex r1 = new Regex(regexPattern.TrimEnd(null));
return r1.Match(inputValue.TrimEnd(null)).Success;
}


好了,Build后Deploy到你的Target database就OK了,VisualStudio會自動注冊這個程序集的。如果,你想手動注冊程序集,可執行以下的T-SQL:

復制代碼 代碼如下:


CREATE ASSEMBLY [RegExCLR] FROM 'RegExCLR.dll';

-- Add the REGEX function. We want a friendly name
-- RegExMatch rather than the full namespace name.
-- Note the way we have to specify the Assembly.Namespace.Class.Function
-- NOTE the RegExCLR.RegExCLR
-- (one is the assembly the other is the namespace)
CREATE FUNCTION RegExMatch ( @inputCalue NVARCHAR(4000),
@regexPattern NVARCHAR(4000) ) RETURNS BIT
AS EXTERNAL NAME RegExCLR.RegExCLR.ClrClass.RegExMatch;


OK, 一切OK的后,我們來測試下:

select COUNT(1) from Threads where dbo.RegExMatch(ThreadId,'^[{|/(]?[0-9a-fA-F]{8}[-]?([0-9a-fA-F]{4}[-]?){3}[0-9a-fA-F]{12}[/)|}]?$')=1
上面的T-SQL是找出Threads表ThreadId是GUID的記錄數。 等于1是匹配,^[{|/(]?[0-9a-fA-F]{8}[-]?([0-9a-fA-F]{4}[-]?){3}[0-9a-fA-F]{12}[/)|}]?$ 匹配GUID的正則表達式。

完了,希望這篇POST對您有幫助。

您可能對以下POST感興趣:

SQLSERVER2008中CTE的Split與CLR的性能比較

SQLSERVER使用CLR Stored Procedure導出數據到Excel
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 章丘市| 巴马| 囊谦县| 大宁县| 平昌县| 江陵县| 泰宁县| 乌兰县| 曲麻莱县| 阿城市| 南靖县| 云浮市| 延安市| 子长县| 嘉鱼县| 湖口县| 潮安县| 长汀县| 二手房| 靖边县| 东丰县| 安宁市| 抚顺市| 都兰县| 宜昌市| 江川县| 昆明市| 千阳县| 天峨县| 满城县| 常山县| 新郑市| 鹰潭市| 邓州市| 丰镇市| 万盛区| 班戈县| 石嘴山市| 成武县| 东乡县| 洞头县|