sql server 正则表达式 [英] sql server regex

查看:88
本文介绍了sql server 正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 SQL Server (2012) 中,我有一个带有数值的字段.该字段的类型为 int.假设数据库中的字段包含 123456789.我是这样搜索的:

In SQL Server (2012) I have a field with numeric values. The field is of type int. Let's say that the field in the db contains 123456789. I'm searching like this:

select * from table1 where field1 like '[1-9]{0,2}3456789'

我也试过 '^[1-9]{0,2}$3456789'

两者都不起作用.我做错了什么?

Both are not working. What am I doing wrong?

推荐答案

SQL Server 本身不支持正则表达式.您需要为此安装 CLR 程序集.

SQL Server does not natively support Regular Expressions. You would need to install a CLR assembly for this.

LIKE 模式语法不支持量词,因此不使用 CLR 的唯一选择是将其扩展.

The LIKE pattern syntax does not support quantifiers so without using CLR the only alternative is to expand it out.

where field1 like '3456789' 
 or  field1 like '[1-9]3456789'  
 or  field1 like '[1-9][1-9]3456789' 

这篇关于sql server 正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆