[英]Query with a field to with a specific format
I have an SQL table with a field REFERENCE
.我有一个带有
REFERENCE
字段的 SQL 表。 Most of the references are like this: A123B45*
I mean:大多数参考文献都是这样的:
A123B45*
我的意思是:
1 letter, 3 digits, 1 letter, 2 digits, anything
But some are different , like AB123C12
they start by 2 letters.但有些是不同的,比如
AB123C12
它们以2 个字母开头。
I want to make a query to get only the lines with a reference corresponding to the first example A123B45*
.我想进行查询以仅获取与第一个示例
A123B45*
对应的引用的行。
I already tried this:我已经试过了:
select REFERENCE from facture where REFERENCE REGEXP "[a-zA-Z][0-9]{3}[a-zA-Z][0-9]{2}[.]*"
But this doesn't work because I have also lines starting by two letters .但是,这并不工作,因为我也有两个字母开始行。
Add ^
anchor , since reference
must start from (not contain ) the regular expression:添加
^
锚,因为reference
必须从开始(不含)的正则表达式:
select REFERENCE
from facture
where REFERENCE REGEXP "^[a-zA-Z][0-9]{3}[a-zA-Z][0-9]{2}"
What's going on:这是怎么回事:
AB123C12 <-- doesn't start from the pattern
^ ^
|-----| <-- but contains the pattern
that's why you had false positives这就是为什么你有误报
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.