1

由于我是 REGEX 的新手,所以我无法解决以下问题。

请分享一些与解析器相关的链接,以便我学习。

我在解决 SQL 语句下面的 int 时遇到问题。它的更多行添加到先前的 INPUT 中。

请帮我解决这个问题。

DECLARE
numerator   NUMBER;
BEGIN
SELECT x, y INTO numerator, denominator FROM result_table, s_Table
WHERE sample_id = 8;
the_ratio := numerator/denominator;
IF the_ratio > lower_limit THEN
INSERT INTO 
ratio VALUES (table, coloum);
ELSE
INSERT INTO onemoreTable VALUES (table, -1);
END IF;
COMMIT;
delete from     --some comment
xyz where id=17;
EXCEPTION
WHEN ZERO_DIVIDE THEN
INSERT INTO ratio VALUES (table, 0);
COMMIT;
WHEN OTHERS THEN
ROLLBACK;
END;

输出:

SELECT from: result_table, s_Table
INSERT into: ratio
INSERT into: onemoreTable
DELETE from: xyz
INSERT into: ratio
4

1 回答 1

1

这是使用正则表达式的基于 Perl 的解决方案:

$input =~s/--.*?\n//g; # delete the comments.
$input =~s/\s+/ /g; # replace multiple white space with single space.
while($input=~m/((?:insert into)|(?:delete from)) (\w+)/ig) { 
        print "$1 : $2\n";    
}

解析 SQL 的正确方法是使用解析器而不是使用正则表达式。

于 2010-08-25T06:08:24.373 回答