不使用正则表达式的字母和数字排列的SQL匹配 [英] SQL match on letter and number arrangement without using regular expressions

查看:163
本文介绍了不使用正则表达式的字母和数字排列的SQL匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以为MySQL编写一条SQL语句,而无需使用REGEXP来查找匹配特定字母/数字排列的所有行?

Is it possible to write an SQL statement for MySQL which finds all rows which match a specific arrangement of letters/numbers without using REGEXP?

即从myTable中选择myCol,其中myCol =' {number} {number} {letter} '

i.e. SELECT myCol FROM myTable WHERE myCol='{number}{number}{letter}'

应返回12X和34Y,但不能返回123X或34YY

Should return 12X and 34Y but not 123X or 34YY

[我之前曾问过类似的问题-( SQL字母和数字排列匹配).不同之处在于,我发现我无法在正使用的ADO.Net驱动程序中使用正则表达式.而且,由于我使用的Visual Studio 2003与更高版本不兼容,因此无法更新它.]

[I have asked a similar question before- ( SQL match on letter and number arrangement). The difference is that I have discovered that I cannot use regular expressions with the ADO.Net driver I am using. Whatsmore, I cannot update it since I am using Visual Studio 2003 which is not compatible with later versions.]

推荐答案

尝试一下:

SELECT myCol 
FROM myTable 
WHERE SUBSTRING(myCol, 1 , 1) >= 'A' 
AND SUBSTRING(myCol, 1 , 1) <= 'Z' 
AND SUBSTRING(myCol, 2 , 1) >= 'A' 
AND SUBSTRING(myCol, 2 , 1) <= 'Z' 
AND SUBSTRING(myCol, 3 , 1) >= '0' 
AND SUBSTRING(myCol, 3 , 1) <= '9'

这篇关于不使用正则表达式的字母和数字排列的SQL匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆