Je le format suivant d'être accepté dans ma procédure stockéeBriser une chaîne de procédure stockée dans la table temporaire mysql
hat=blue,yellow:=:jacket=leather,jean:=:shoes=nike,puma,umbro,converse
donc je voudrais l'accepter et l'insérer dans une table temporaire comme
product | inventory
-------------------
hat | blue
-------------------
hat | yellow
-------------------
jacket | leather
-------------------
jacket | jean
-------------------
shoes | nike
-------------------
shoes | puma
-------------------
shoes | umbro
-------------------
shoes | converse
-------------------
j'ai donc la procédure stockée suivante accepter cela, mais je me bats pour le casser dans les parties (nouveau à MySQL)
tiré d'un exemple ici Split a string and loop through values in MySql Procedure une d étant le modifier un peu
DELIMITER $$
DROP PROCEDURE IF EXISTS `inventoryHandle` $$
CREATE PROCEDURE `inventoryHandle`(_list MEDIUMTEXT)
BEGIN
DECLARE _next TEXT DEFAULT NULL;
DECLARE _nextlen INT DEFAULT NULL;
DECLARE _value TEXT DEFAULT NULL;
CREATE TEMPORARY TABLE productInventory (
product VARCHAR(50) NOT NULL
, inventory VARCHAR(50) NOT NULL
);
iterator:
LOOP
IF LENGTH(TRIM(_list)) = 0 OR _list IS NULL THEN
LEAVE iterator;
END IF;
SET _next = SUBSTRING_INDEX(_list,':=:',1); -- gets me the hats=blue,yellow string
SET _nextlen = LENGTH(_next);
SET _value = TRIM(_next);
INSERT INTO productInventory (product, inventory) VALUES (***); -- not sure how to handle here
SET _list = INSERT(_list,1,_nextlen + 1,'');
END LOOP;
END $$
DELIMITER ;
* "Pris d'un exemple" * [en effet] (https://stackoverflow.com/a/37231257/1695906). S'il vous plaît n'oubliez pas de fournir l'attribution. –
oui, j'ai ajouté l'attribution maintenant - merci – jedgard
Merci. Ce qui est amusant, ici, c'est que ma première pensée a été "J'ai répondu à une question très similaire, une fois ..." –