如何在mariadb的程序中使用正则表达式?

时间:2018-09-25 14:17:16

标签: regex mariadb procedure

我的环境:

windows 7 sp1 64bit

mariadb 10.3.8

我创建一个过程为:

CREATE OR REPLACE PROCEDURE `num_of_zone`(IN zone_reg varchar(1000))
BEGIN
  DECLARE person_num INT;
  SELECT COUNT(*) INTO person_num FROM person WHERE address REGEXP zone_reg;
  SELECT person_num FROM DUAL;
END;

现在我将其称为cpu goto 100%,稍后,我的mariadb服务将停止。 但是,如果我使用特定的zone_reg运行sql,例如:

SELECT COUNT(*) INTO person_num FROM person WHERE address REGEXP 'River [1-4]U.*';

那会很好。

我怎么了?

我的测试数据库和数据:

CREATE TABLE flup_person (
  person_id int(11) NOT NULL,
  address varchar(255) NOT NULL DEFAULT '',
  flup_year int(11) NOT NULL DEFAULT 0,
  flup_quarter int(11) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


CREATE OR REPLACE VIEW yq AS
SELECT YEAR(CURDATE()) AS flup_year, QUARTER(CURRENT_TIMESTAMP()) AS flup_quarter
UNION
SELECT YEAR(CURDATE() - INTERVAL 1 QUARTER) AS flup_year, QUARTER(CURDATE() - INTERVAL 1 QUARTER) AS flup_quarter
UNION
SELECT YEAR(CURDATE() - INTERVAL 2 QUARTER) AS flup_year, QUARTER(CURDATE() - INTERVAL 2 QUARTER) AS flup_quarter
UNION
SELECT YEAR(CURDATE() - INTERVAL 3 QUARTER) AS flup_year, QUARTER(CURDATE() - INTERVAL 3 QUARTER) AS flup_quarter;

CREATE OR REPLACE VIEW flup_view AS
SELECT p.person_id, p.address
FROM flup_person AS p LEFT JOIN yq
USING (flup_year, flup_quarter)
GROUP BY p.person_id;

CREATE OR REPLACE PROCEDURE num_of_zone(IN zone_reg varchar(1000))
BEGIN
  DECLARE person_num int;
  SELECT COUNT(*) INTO person_num FROM flup_view WHERE address REGEXP zone_reg;
  SELECT person_num FROM DUAL;
END;

INSERT INTO flup_person(person_id, address, flup_year, flup_quarter)
VALUES
(2, 'River 1Uz', 2018, 1),
(3, 'River 2Uz', 2018, 3),
(4, 'River 15Ud', 2018, 2);

最后,我用:

CALL num_of_zone('River [1-2].*');

它将停止mariadb。

但是使用:

SELECT COUNT(*) FROM flup_view WHERE address REGEXP 'River [1-2].*';

没关系。

0 个答案:

没有答案