您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息

使用VS2013创建数据库项目实现MSSQL正则方法

2024/3/28 15:55:45发布5次查看
实现步骤 1:创建数据库项目 2:引用相关库,简单实现代码如下 using system;using system.data;using system.data.sqlclient;using system.data.sqltypes;using microsoft.sqlserver.server;using system.text.regularexpressions;public partial class reg
实现步骤
1:创建数据库项目
2:引用相关库,简单实现代码如下
using system;using system.data;using system.data.sqlclient;using system.data.sqltypes;using microsoft.sqlserver.server;using system.text.regularexpressions;public partial class regexsql{ [microsoft.sqlserver.server.sqlfunction] public static sqlboolean regex_ismatch(string input, string regex) { return new sqlboolean(regex.ismatch(input, regex, regexoptions.ignorecase)); } [microsoft.sqlserver.server.sqlfunction] public static sqlstring regex_match(string input, string regex) { return new sqlstring(regex.match(input, regex, regexoptions.ignorecase).value); }}
3:在mssql中添加程序集
如果失败请先执行脚本
exec sp_configure 'show advanced options', '1';goreconfigure;goexec sp_configure 'clr enabled', '1'goreconfigure;exec sp_configure 'show advanced options', '1'; go alter database [db_name] set trustworthy on;go
4:创建关联函数
create function regex_match( @input as nvarchar(1000), @regex as nvarchar(100) )returns nvarchar(1000)as external name iftrue_regex.regexsql.regex_match;gocreate function regex_ismatch( @input as nvarchar(1000), @regex as nvarchar(100) )returns bitas external name iftrue_regex.regexsql.regex_ismatch;go
5:使用函数实现正则匹配 select dbo.regex_ismatch('abcde123asdf234','[b-s]+') select dbo.regex_match('abcde123asdf234','[b-s]+')
注:以上实现是基于framework3.5,在framework4.0下添加程序集会出错,同样方式可以实现很多数据库本身不便实现的功能,如:调用web api、webservice等
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录