Function ExtractTableNames(sqlText As String, ParamArray schemas() As Variant) As String
Dim matches As Object
Dim regex As Object
Dim i As Integer
Dim schema As String
Dim pattern As String
Dim result As String
Dim match As Object
Dim tableName As String
Dim dict As Object
Set regex = CreateObject("VBScript.RegExp")
regex.Global = True
regex.IgnoreCase = True
' スキーマパターンを正規表現用に連結(例:AA_DB|BB_DB|CC_DB)
pattern = "\b(" & Join(schemas, "|") & ")\.[A-Z0-9_]+\b"
regex.Pattern = pattern
Set matches = regex.Execute(sqlText)
Set dict = CreateObject("Scripting.Dictionary")
For Each match In matches
tableName = match.Value
If Not dict.exists(tableName) Then
dict.Add tableName, True
If result <> "" Then result = result & ","
result = result & tableName
End If
Next
ExtractTableNames = result
End Function
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme