DROP PROCEDURE IF EXISTS `test223`$$ CALL test223()
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `test223`()
BEGIN
DECLARE xmlDoc TEXT;
DECLARE i INT ;
DECLARE coun INT;
DECLARE child1 VARCHAR(400);
DECLARE child2 VARCHAR(400);
SET i =1;
SET xmlDoc = '<Data><parent><child1>Example 1</child1><child2>Example 2</child2></parent><parent><child1>Example 3</child1><child2>Example 5</child2></parent><parent><child1>Example 5</child1><child2>Example 6</child2></parent></Data>';
SET coun = ExtractValue(xmlDoc, 'count(/Data/parent/child1)');
DROP TEMPORARY TABLE IF EXISTS `parent`;
CREATE TEMPORARY TABLE parent ( child1 VARCHAR(400),
child2 VARCHAR(400) );
WHILE i <= coun DO
INSERT INTO parent
SELECT ExtractValue(xmlDoc, '//parent[$i]/child1'), ExtractValue(xmlDoc, '//parent[$i]/child2');
SET i = i+1;
END WHILE;
SELECT * FROM parent;
END$$
DELIMITER ;
Response Table :
+---------------------+ | Child1 | Child2 | |-----------|-----------| |Example 1 |Example 2| |-----------|-----------| |Example 3 |Example 5| |-----------|-----------| |Example 5 |Example 6| |-----------|-----------|
No comments:
Post a Comment