REGEXP
在 MYSQL 中使用函数怎么样?
SELECT *
WHERE tbl_IncomingChecks.Client REGEXP concat('%', @Client, '%')
ORDER BY tbl_IncomingChecks.Client;
或者只是简单地使用 @client 作为REGEXP
查找包含此客户端名称的所有客户端:
SELECT *
WHERE tbl_IncomingChecks.Client REGEXP @Client
ORDER BY tbl_IncomingChecks.Client;
根据 OP 在 RDBMS 上作为 MS ACCESS 的更新
如果您有更复杂的模式,您可以Regexp
在 MS Access UDF 中使用对象。但是在当前情况下,您最好使用LIKE Concat('*',@client,'*')
'-- you may even send the pattern as a parameter
'-- you may also send all the clients into the UDF itself for matching
'-- returning a set of matched names string
Function regexpFunc(ByRef strInput As String, ByRef clientName as String) As Boolean
Dim myRegex As New RegExp
Dim matchSet As MatchCollection
With myRegex
.MultiLine = False
.Global = True
.IgnoreCase = False
End With
myRegex.Pattern = clientName
If myRegex.Test(strInput) Then
'matching values can be collected here
'-- Set matchSet = myRegex.Execute(strInput)
RegexFunc = True
Else
RegexFunc = False
End If
End Function
以下是在查询中使用上述函数的方法:
SELECT *
FROM MYTABLE
WHERE RegexpFunc(tbl_IncomingChecks.Client, "Smith")
ORDER BY tbl_IncomingChecks.Client;