2

犠牲者とその数を受け入れるプロシージャを作成しようとしています。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 :(ここから)

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, '')
4

1 に答える 1

1

インクリメントすると、ユーザー変数@startindexが失わ@れます。

SET @startindex=startindex+1;
-- Should be:
SET @startindex = @startindex+1;
于 2012-08-31T13:24:29.183 に答える