字段列表中的mysql Unknown列变量 [英] mysql Unknown column variable in the field list
本文介绍了字段列表中的mysql Unknown列变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写一个程序来接受受害者及其人数.victims
参数将包含类似'123,321,222'
的值,并且我正在使用一个函数
调用SPLIT_STR_FUNCTION
将文本拆分为逗号分隔的值.然后我
会将每个值插入数据库.
I am trying to write a procedure which will accept victims and their count.The victims
parameter will contain the values like this '123,321,222'
and I am using a function
call SPLIT_STR_FUNCTION
to split the text into comma seperated values. Then I
will insert each value in the database.
这是我的程序:
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
错误: 字段列表中的未知列起始索引
SPLIT_STR_FUNCTION:(来自这里)
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, '')
推荐答案
递增时,您的用户变量@startindex
缺少其@
:
Your user variable @startindex
is missing its @
when you increment it:
SET @startindex=startindex+1;
-- Should be:
SET @startindex = @startindex+1;
这篇关于字段列表中的mysql Unknown列变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文