Comma separated variable in MySQL

后端 未结 2 600
臣服心动
臣服心动 2021-01-23 07:13

I want to create a stored procedure in MySQL and one of the input parameters will need to be a comma separated list of integers. How do I loop through each integer and run an up

2条回答
  •  有刺的猬
    2021-01-23 07:46

    I got it...

    DECLARE i INT DEFAULT 0;
    DECLARE curId VARCHAR(100);
    WHILE SPLIT_STR(in_IdCommaDelimited, ',', i) != '' DO
    
        SET curId = SPLIT_STR(in_IdCommaDelimited, ',', i);
    
        UPDATE MyTable SET OrderNumber = i WHERE Id = curId;
    
        SET i = i + 1;  
    
    END WHILE;
    

提交回复
热议问题