我正在尝试编写一个接受受害者及其统计的程序。victims
参数将包含像'123,321,222'
这样的值,我正在使用一个函数
调用SPLIT_STR_FUNCTION
将文本拆分为逗号分隔值。然后我
将在数据库中插入每个值。
这是我的程序:
CREATE DEFINER=`root`@`localhost` PROCEDURE `InsertPost`( in pmsg text, in pthumbPath text, in ppath text, in puserid bigint, in count int, in victims text)
BEGIN
INSERT INTO posts(path,thumbpath,msg,userid) VALUES(ppath,pthumbpath,pmsg,puserid);
SET @lastpostid = (SELECT postid FROM posts ORDER BY postid DESC LIMIT 1);
SET @startindex=1;
WHILE @startindex <= count DO
SET @IndividualIDs=convert((select SPLIT_STR_Function(victims, ',', @startindex)),signed);
SET @startindex=startindex+1;
INSERT INTO victims(victimid,postid) VALUES(@IndividualIDs,@lastpostid);
end WHILE;
END
错误: 字段列表中的未知列startindex
SPLIT_STR_FUNCTION:(来自here)
CREATE DEFINER=`root`@`localhost` FUNCTION `SPLIT_STR_Function`(
x VARCHAR(255),
delim VARCHAR(12),
pos INT
)
RETURNS varchar(255) CHARSET latin1
RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos),
LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1),
delim, '')
答案 0 :(得分:0)
您的用户变量@startindex
在递增时会遗漏@
:
SET @startindex=startindex+1;
-- Should be:
SET @startindex = @startindex+1;