- DELIMITER $$
- DROP PROCEDURE IF EXISTS `array`$$
- CREATE PROCEDURE `array`()
- BEGIN
- SET @array_content="www mysql com hcymysql blog 51cto com";
- SET @i=1;
- SET @count=CHAR_LENGTH(@array_content)-CHAR_LENGTH(REPLACE(@array_content,' ','')) + 1;
- -- 得出数组成员总数
- CREATE TABLE test.tmp(field1 VARCHAR(100));
- WHILE @i <= @count
- DO
- INSERT INTO test.tmp VALUES
- (SUBSTRING_INDEX(SUBSTRING_INDEX(@array_content,' ',@i),' ',-1));
- -- 依次插入每个成员
- SET @i=@i+1;
- END WHILE;
- END$$
- DELIMITER ;
测试: