存储过程无法循环字符串数组 [英] stored procedure cannot loop an array of string
本文介绍了存储过程无法循环字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好日子!
我有一个mysql存储过程,它应该遍历任意数组的字符串(可以这么说)。就是这样:
Good day everyone !
i have a mysql stored procedure that should loop through an arbitrary array of strings (so to speak). here's it:
CREATE PROCEDURE StupidProcedure (INOUT Stringarray VARCHAR(100), IN msg VARCHAR (100) )
BEGIN
/*Table loop variable*/
DECLARE indx INT;
DECLARE len INT;
DECLARE valu INT;
SET @indx = 0;
SET @len = 0;
WHILE LOCATE(',', @Stringarray , @indx + 1) > 0 DO
SET @len = LOCATE(',', @Stringarray , @indx + 1) - @indx;
SET @valu = SUBSTRING(@Stringarray , @indx, @len);
SELECT CONCAT(@msg, @valu) INTO msg; /* For Debugging purpose*/
SET @indx = LOCATE(',', @Stringarray , @indx + @len) + 1; /*increment loop*/
END WHILE;
END
现在,我需要确保连接的@msg在@Stringarray之后收到了所有数据环。使用PHP,我只是这样做:
Now, i needed to be sure that concatenated @msg has received all data in @Stringarray after the loop. Using php, i simply did this:
$StupidArray = "Boys, are, not, smiling, at, all,";
if (!$db->query(" SET @msg = ''; SET @Stringarray = '\' $StupidArray '\'; " ) || !$db->query(" CALL StupidProcedure (@Stringarray, @msg)") ){
echo "CALL to StupidProcedure failed:".print_r($db->errorInfo());
}else{
$res = $db->query("SELECT @msg as _p_out");
$row = $res->fetch();
print_r($row['_p_out']);
}
What i got in return was 'all', the last is $StupidArray. what am i doing wroing ? OR is it my loop thats failing ?
thanks.
推荐答案
StupidArray =男孩,是,不,微笑,在,所有,;
if(!
StupidArray = "Boys, are, not, smiling, at, all,"; if (!
db-> query(SET @msg =''; SET @Stringarray ='\'
db->query(" SET @msg = ''; SET @Stringarray = '\'
StupidArray'\';)||!
StupidArray '\'; " ) || !
这篇关于存储过程无法循环字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文