How to properly loop in a stored function on MySQL?

后端 未结 2 956
被撕碎了的回忆
被撕碎了的回忆 2021-01-05 01:49

I am having some difficulty getting a pretty simple stored procedure right. Consider the following article table snippet:

id    replaced_by     baseID
 1             


        
2条回答
  •  死守一世寂寞
    2021-01-05 02:09

    From mysql :

    If the query returns no rows, a warning with error code 1329 occurs (No data), and the variable values remain unchanged

    So you have an infinite loop when no records found with a given x (y remains unchanged) Try SET y = (SELECT id ....) instead or add SET y = null before your select statement (it should be the first statement in the loop)

提交回复
热议问题