Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
类SQL子句的特殊模式_Sql_Sql Server - Fatal编程技术网

类SQL子句的特殊模式

类SQL子句的特殊模式,sql,sql-server,Sql,Sql Server,需要特殊模式来查找13个长度字符的值,12个字符中的第一个是数字,例如119910023525P 有两种模式: LIKE '____________P' 或 需要像'[0-9]{12}p' 这在MS-SQL Server中是可能的?也许REGEXP()函数将帮助您完成此任务。TSQL模式语法中没有量词 你可以用 LIKE REPLICATE('[0-9]',12) + 'P' 您可以使用以下逻辑: (x like '%P' and x not like '%[^0-9]%P' and le

需要特殊模式来查找13个长度字符的值,12个字符中的第一个是数字,例如
119910023525P
有两种模式:

LIKE '____________P' 

需要像
'[0-9]{12}p'

这在MS-SQL Server中是可能的?

也许REGEXP()函数将帮助您完成此任务。

TSQL模式语法中没有量词

你可以用

LIKE REPLICATE('[0-9]',12) + 'P'

您可以使用以下逻辑:

(x like '%P' and x not like '%[^0-9]%P' and len(x) = 13)

但这与手动复制12次的输入量差不多。

像“[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]p”这样的输入有什么问题吗?@pmbAustin它没有任何问题,只是问sql server是否支持查询中的正则表达式<代码>[0-9]{12}P比查询太长时更好。@pmbAustin这不是很好的人类可读性。为了推断该模式是在寻找12位数字后加上一个P,您需要将它们全部计算在内。这不是一个sql server函数回答得很好,但正如您所说的,复制的
[0-9]
12倍比它短=))
(x like '%P' and x not like '%[^0-9]%P' and len(x) = 13)