我使用的函数用于覆盖包含以逗号分隔的名称的列“利益相关者”的字段。 目标是将名称与存储在表“扬声器”中的名称进行比较,它由两列组成:“id_équipe”(包含团队名称auquelle属于介入者名称)和“nom_intervenant”(包含名称列表)。 。那么,目标是将名称与存储在表格中的名称“干预”进行比较。如果结果是肯定的,我们采取代码中列出的步骤。
delimiter |
CREATE FUNCTION DETERMINE1234(s VARCHAR(2000)) RETURNS int(2)
DETERMINISTIC
BEGIN
DECLARE open INT;
DECLARE close INT;
DECLARE someLimit INT;
DECLARE cpt int;
DECLARE cs int;
DECLARE cm int;
DECLARE co int;
DECLARE str VARCHAR(255);
DECLARE toFind VARCHAR(2000);
SET open = 1;
SET close = 1;
SET cpt=0;
SET cs=0;
SET cm=0;
SET co=0;
SET toFind = s ;
SET someLimit = 5;
SET str ='';
WHILE close > 0 and open > 0 and someLimit > 0 DO
SET someLimit = someLimit -1;
SET toFind = SUBSTRING(toFind,open);
SET close = locate(',',toFind);
IF close > 2 THEN
SET str =SUBSTRING(toFind,2,close-2);
IF (Select id_equipe from intervenant where nom_intervenant=str='Deploiement Radio') OR
(Select id_equipe from intervenant where nom_intervenant=str='Optimisation Huawei')OR
(Select id_equipe from intervenant where nom_intervenant=str='Optimisation NSN') OR
(Select id_equipe from intervenant where nom_intervenant=str='Support BSS Nord') OR
(Select id_equipe from intervenant where nom_intervenant=str='Support BSS Sud') THEN SET co=1;
END IF;
IF (Select id_equipe from intervenant where nom_intervenant=str='QDF') OR
(Select id_equipe from intervenant where nom_intervenant=str='Supervision Back Office') THEN SET cs=1;
END IF;
IF (Select id_equipe from intervenant where nom_intervenant=str='Maintenance') THEN SET cm=1;
END IF;
SET toFind = SUBSTRING(toFind,close);
END IF;
END WHILE;
SET cpt=co+cs+cm;
return cpt;
END |
delimiter;
这是我使用的SQL查询:
update incident set groupes_intervenants=DETERMINE12(intervenants) WHERE Status like 'Closed'
结果将存储在“利益相关者群体”栏中。 提前谢谢你。