2

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.

here is my procedure :

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

Error: Unknown column startindex in the field list

SPLIT_STR_FUNCTION: (from 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, '')
1
  • thnx i wasted hours on this silly mistake. :) Commented Aug 31, 2012 at 13:20

1 Answer 1

1

Your user variable @startindex is missing its @ when you increment it:

SET @startindex=startindex+1;
-- Should be:
SET @startindex = @startindex+1;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.