我正在尝试拆分PL / SQL intructions。我带来了以下模式:
splitter_re = '(DECLARE.+?END;)\n+|;\n+'
我有以下PL / SQL代码:
CREATE TABLE bk_temp1_kb AS
SELECT DISTINCT bk_c, bk_o, bk_r, bk_m
FROM www2013_02;
DECLARE
time_val NUMBER;
BEGIN
SELECT day INTO time_val
FROM days
WHERE day_desc = TO_CHAR(SYSDATE - 1);
EXECUTE IMMEDIATE
'DROP TABLE telep';
EXECUTE IMMEDIATE
'CREATE TABLE telep AS
SELECT cc,
dao,
a,
nam
FROM prodc
WHERE timer = ' || time_val;
END;
DROP TABLE kart;
CREATE TABLE kart AS
SELECT b.dwp
FROM t_prod_new b
WHERE b.task = 'CARD';
split()的结果是:
['CREATE TABLE bk_temp1_kb AS\nSELECT DISTINCT bk_c, bk_o, bk_r, bk_m\nFROM www2
013_02', None, '', "DECLARE\n time_val NUMBER;\nBEGIN\n SELECT day INTO time_v
al\n FROM days\n WHERE day_desc = TO_CHAR(SYSDATE - 1);\n \n EXECUTE IMMEDIAT
E\n 'DROP TABLE telep';\n \n EXECUTE IMMEDIATE\n 'CREATE TABLE telep AS\n SE
LECT cc,\n dao,\n a,\n nam \n FROM prodc\n WHERE timer =
' || time_val;\nEND;", 'DROP TABLE kart', None, "CREATE TABLE kart AS\nSELECT b
.dwp\nFROM t_prod_new b\nWHERE b.task = 'CARD';"]
这很好,但我有无元素。模式有什么问题?
答案 0 :(得分:0)
您有无元素,因为您有()
制作的没有内容的小组
'(x)|y'
matches "x" with ("x", ...)
matches "y" with (None, ...)
因为第一个(x)
没有匹配
更改
'(DECLARE.+?END;)\n+|;\n+'
到
'(?:DECLARE.+?END;)\n+|;\n+'
删除无。
(?:x)|y
is the same as
x|y
括号不分组