2
我想寫這將接受受害者及其count.The victims
參數將包含類似這樣'123,321,222'
值的程序,我使用的是函數調用 SPLIT_STR_FUNCTION
分割文本分成逗號分隔值。然後我將 將每個值插入到數據庫中。MySQL的未知列變量
這裏是我的方法:
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, '')
thnx我在這個愚蠢的錯誤上浪費了幾個小時。 :) – Mj1992
我會回答。 –