Hi

I am converting a stored procedure from mssql to mysql with two cursors in it.
Here is the code I have written so far. The procedure works fine with the first cursor but when I add the inner cursor it doesn't compile.

I have left out the create procedure statement. The error is reported to be near where the second cursor is declared.
Thankful for any help


BEGIN

DECLARE i_user int;
DECLARE i_index int;
DECLARE i_id int;
DECLARE done BOOLEAN DEFAULT 0;
DECLARE done2 BOOLEAN DEFAULT 0;




DECLARE order_cursor CURSOR
FOR
SELECT user FROM orders;


DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done=1;

OPEN order_cursor;

REPEAT

FETCH order_cursor INTO i_user;

SET i_index = 0;




-- inner cursor

DECLARE order_cursor2 CURSOR FOR
SELECT
id
FROM
orders
WHERE
user = i_user
ORDER BY
date_time ASC;


DECLARE CONTINUE HANDLER FOR SQLSTATE '02000'
SET done2 = 1;

open order_cursor2;



FETCH order_cursor2 INTO i_id;

SET i_index = i_index + 1;

UPDATE
orders
SET
payment_order = i_index
WHERE
id = i_id;





UNTIL done2 END REPEAT;
CLOSE order_cursor2;

-- inner cursor end



UNTIL done END REPEAT;
CLOSE order_cursor;




END