MySQL中不支持数组,但又想利用C语言数组来需要的数据,故:
DROP PROCEDURE IF EXISTS sp_array;
CREATE PROCEDURE sp_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;
# 得出数组成员总数
DROP TABLE IF EXISTS test.tmp;
CREATE TEMPORARY TABLE test.tmp(field1 VARCHAR(100));
WHILE @i <= @count DO
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(@array_content,' ',@i),' ',-1);
# 依次显示每个成员
SET @i=@i+1;
END WHILE;
END;
DROP PROCEDURE IF EXISTS sp_array;
CREATE PROCEDURE sp_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;
# 得出数组成员总数
DROP TABLE IF EXISTS test.tmp;
CREATE TEMPORARY TABLE test.tmp(field1 VARCHAR(100));
WHILE @i <= @count DO
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(@array_content,' ',@i),' ',-1);
# 依次显示每个成员
SET @i=@i+1;
END WHILE;
END;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26855487/viewspace-764769/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/26855487/viewspace-764769/