If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Help with cursor in mysql

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-24-09, 06:35
steohl steohl is offline
Registered User
 
Join Date: Jul 2005
Posts: 25
Help with cursor in mysql

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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On