我有一个查询,其中一个值由 UDF 返回:
select name,coord,convertCoord(coord) from testTable;
convertCoord()
使用Regex
和MatchCollection
对象返回其值:
Dim re As New RegExp
Dim mtch As Match
Dim matches As MatchCollection
Function convertCoord(str As String) As String
re.Pattern = "(find|this)pattern"
Set matches = re.Execute(str)
If matches.Count > 0 Then
Set mtch = matches(1)
convertCoord = mtch.Value
Else
convertCoord = ""
End If
End Function
我正在尝试加快查询速度,我想知道是否有办法制作 , 的一个实例re
,mtch
并且matches
每次调用convertCoord()
. 如果我理解正确,查询中的每个结果行都会调用convertCoord()
,它会重复构造和破坏所有对象,并且所有这些对象的创建都会减慢查询速度。
还是它们已经是静态的,因此只构造了一次,因为我已经在函数之外声明了它们?