字母和数字排列的 SQL 匹配 [英] SQL match on letter and number arrangement
问题描述
是否可以编写一个 SQL 语句来查找与特定字母/数字排列相匹配的所有行?
Is it possible to write an SQL statement which finds all rows which match a specific arrangement of letters/numbers?
即SELECT myCol FROM myTable WHERE myCol='
应该返回 12X 和 34Y 但不是 123X 或 34YY
Should return 12X and 34Y but not 123X or 34YY
我正在使用 MySQL.
I am using MySQL.
推荐答案
我还没有在这台机器上安装 MySQL 来测试,但我认为
I haven't got MySQL on this machine to test but I think
SELECT myCol
FROM myTable
WHERE myCol REGEXP '^[0-9][0-9][A-Z]$'
应该这样做.^
是字符串开头的锚点,$
是字符串结尾的锚点,其余的应该不言自明.
Should do it. ^
is an anchor for start of string, $
for end of string and the rest should be self explanatory.
看起来你也可以使用 REGEXP '^[[:digit:]][[:digit:]][[:alpha:]]$'
但完全未经测试,只是离开文档.
Looks like you could also use REGEXP '^[[:digit:]][[:digit:]][[:alpha:]]$'
but completely untested and just going off the docs.
这篇关于字母和数字排列的 SQL 匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!