1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
delimiter //
CREATE TABLE intervention
(id_incident int, update_action varchar(200), status varchar(10), intervenants varchar(200))
//
INSERT INTO intervention
(id_incident, update_action, status)
VALUES
(1, '(julien) La demande n''est pas claire. (francois) le client veux rouge. (jean) Ok rouge fournis au client', 'closed'),
(2, '(julien) Envoyé au client hier soir. (client) Ok bien reçu', 'closed' ),
(3, '(patron) Urgent!!! (julien) Expédié en livraison 2h. (client) Ho ça pouvait attendre le mois prochain, mais merci.', 'closed')
//
CREATE FUNCTION TRANSFORM(s VARCHAR(2000)) RETURNS varchar(2000)
DETERMINISTIC
BEGIN
DECLARE open INT;
DECLARE close INT;
DECLARE someLimit INT;
DECLARE str VARCHAR(2000);
DECLARE toFind VARCHAR(2000);
SET open = 1;
SET close = 1;
SET toFind = s ;
SET someLimit = 5;
SET str = '';
WHILE close > 0 and open > 0 and someLimit > 0 DO
SET someLimit = someLimit -1;
SET open = locate('(',toFind);
IF open > 0 THEN
SET toFind = SUBSTRING(toFind,open);
SET close = locate(')',toFind);
IF close > 2 THEN
SET str = concat(str,',',SUBSTRING(toFind,2,close-2));
SET toFind = SUBSTRING(toFind,close);
END IF;
END IF;
END WHILE;
return SUBSTRING(str,2);
END//
update intervention set intervenants = TRANSFORM(update_action) where status = 'closed'//
select * from intervention // |
Partager