Special Pattern by SQL LIKE clause

问题: Need special pattern for finding values that are 13 length chars, first of 12 are numbers for example 119910023525P There are 2 Pattern : LIKE '____________P' or LI...

问题:

Need special pattern for finding values that are 13 length chars, first of 12 are numbers for example 119910023525P There are 2 Pattern :

LIKE '____________P' 

or

LIKE '[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'

Need something as '[0-9]{12}P' It's Possible In MS-SQL Server ?


回答1:

There are no quantifiers in the TSQL pattern syntax.

You can use

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

回答2:

You could use this logic:

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

But that is about the same amount of typing as just manually replicated [0-9] 12 times.


回答3:

Maybe the REGEXP() function will help you with this task.

  • 发表于 2019-01-23 08:27
  • 阅读 ( 199 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除