I have the following format being accepted into my stored procedure
hat=blue,yellow:=:jacket=leather,jean:=:shoes=nike,puma,umbro,converse
So i would like to accept this and insert it into a temp table as
product | inventory
-------------------
hat | blue
-------------------
hat | yellow
-------------------
jacket | leather
-------------------
jacket | jean
-------------------
shoes | nike
-------------------
shoes | puma
-------------------
shoes | umbro
-------------------
shoes | converse
-------------------
so I have the following stored procedure accepting this but i am struggling to break it into the parts (new to mysql)
Taken from an example here Split a string and loop through values in MySql Procedure and being modifying it a bit
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 ;