使用MySQL存储过程连续插入多条记录

DELIMITER $$

DROP PROCEDURE IF EXISTS `u1`.`FollowTmpListSave`$$

CREATE DEFINER=`dev`@`%` PROCEDURE `FollowTmpListSave`(inUserId varchar(32),inParamCount int,inFollowId varchar(3000))
BEGIN
	DECLARE i INT(8) DEFAULT 0;
	REPEAT SET i = i + 1;
	INSERT INTO TB_FOLLOWTMP(userId,followId) VALUES (inUserId,TRIM(SUBSTRING_INDEX(SUBSTRING_INDEX(inFollowId, ',', i), ',', -1)));
	UNTIL i >= inParamCount
	END REPEAT;
END$$

DELIMITER ;

你可能感兴趣的:(mysql)