0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

五月のユーザ定義関数(季語)

Last updated at Posted at 2025-05-09
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
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?