perlregex从存储过程中提取表名



我需要从存储过程中提取表名列表,例如SP可能包含一个或多个SQL。

select
t.ticket, t.subsid, null, null
from
    Trans t
where
    subsid = @subsid
select *
from
   Trans t, Cpty c, Book b
where
t.ticket            =  c.ticket

现在我需要提取Trans、Cpty和Book作为表名。sql是如何在perlregex中提取这些信息的多行代码。

请帮忙。

use strict; use warnings;
open my $f, "<", 'input' or die("$!");
my %tables;
while (<$f>) {
    next if !/bfromb/;
    while (<$f>) {
        $tables{$_} = 1 for map { (split)[0] } split(/,/);
        last if !/,s*$/
    }   
}
close $f; 
print join(",", keys %tables), "n";

产品:

Book,Cpty,Trans

最新更新