0

我正在尝试拆分 PL/SQL 指令。我带来了以下模式:

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';"]

它非常好,但我没有元素。模式有什么问题?

4

1 回答 1

0

你有 None 元素,因为你有()没有内容的组

'(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 

括号不分组

于 2013-02-15T10:53:22.127 回答