MySQL Forums
Forum List  »  Stored Procedures

Re: Passing value beteen declared variables within cursor loop
Posted by: Rick James
Date: March 16, 2016 04:37PM

You can do that without a cursor. First verify that this does what you need:

SELECT  field1,
        @prev := IFNULL(id, @prev) AS id
    FROM ( SELECT @prev := 0 ) AS init
    JOIN tbl
    ORDER BY field1;

If that works, then ponder how to JOIN that to the existing table in a multi-table UPDATE.

SQL works best when it does thing en masse; it works poorly if you treat it like a regular programming language and use Cursors.

Options: ReplyQuote

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.