[英]SQL find string plus option char
I try to find a string that match to the following 我尝试找到与以下内容匹配的字符串
989X1[OPTIONAL[a-z]]
This is i tried : 这是我尝试过的:
... where x LIKE '989X1[a-z]?'
... where x LIKE '989X1[a-z]'
but the first query match also " 989X10a
", the other one don't match 989X1
without the optional string. 但是第一个查询也匹配“
989X10a
”,另一个查询不匹配没有可选字符串的989X1
。
With kind regards F Harmsen 此致F Harmsen
The closest you can get using LIKE
would be to use an underscore: 使用
LIKE
可以获得的最接近的结果是使用下划线:
where x = '989X1' OR x LIKE '989X1_'
But this would match any single character, not just alphabets. 但这将匹配任何单个字符,而不仅仅是字母。 Instead, you get closer with
REGEXP
: 相反,您
REGEXP
接近REGEXP
:
where x REGEXP '989X1[a-z]?' -- or REGEXP '^989X1[a-z]?$' for an exact match
Even with REGEXP
it is not exact, because REGEXP
is case insensitive, therefore so is the range. 即使使用
REGEXP
,也不是很精确,因为REGEXP
不区分大小写,因此范围也是如此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.