在MS SQL中,是否有一个运算符可以匹配一个或多个字符? (我很好奇它是否可以在T-SQL中明确实现-其他解决方案肯定是可能的,我在下面的问题示例中使用了其中一种...)
我知道在SQL中,可以使用通配符/类似方法将其显式实现不同程度的成功:
SELECT *
FROM table
-- finds letters aix and then anything following it
WHERE column LIKE 'aix_x%'
在Python中,“ +”运算符允许这样做:
import re
str = "The rain in Spain falls mainly in the plain!"
#Check if the string contains "ai" followed by 1 or more "x" characters:
# finds 'ai' + one or more letters x
x = re.findall("aix+", str)
print(x)
if (x):
print("Yes, there is at least one match!")
else:
print("No match")
答案 0 :(得分:0)
检查字符串是否包含“ ai”后跟1个或多个“ x”字符: 找到'ai'+一个或多个字母x
如果这是您想要的,则:
其中的str类似于'%aix%'
做你想要的。
如果要使用下划线,则下划线是LIKE
表达式中的通配符。 SQL Server中最简单的方法可能是使用字符类:
其中str类似于'%ai [_] x%'
另一个解决方案是:
其中诸如'%ai $ _x%'之类的字符串转义为'$'