MySQL Forums
Forum List  »  Stored Procedures

Table Not Updating
Posted by: Russel James
Date: April 27, 2016 07:22AM

Hi folks,

I am trying to use a cursor for the first time.

The purpose is to update the customers Table by changing the hasOverdueBalance field to 'T' if the customer has any transactions in the SalesLedger table that are overdue.


CREATE DEFINER=`root`@`localhost` PROCEDURE `usp_CustomersUpdateHasOverdueBalance`()
BEGIN

DECLARE loop0_eof BOOLEAN DEFAULT FALSE;
DECLARE tmp_customerID VARCHAR(7);
DECLARE cur0 CURSOR FOR SELECT DISTINCT customerID FROM salesLedger WHERE balance <> 0 AND dueDate < curDate() ORDER BY customerID;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET loop0_eof = TRUE;

OPEN cur0;

loop0: LOOP
FETCH cur0 INTO tmp_customerID;

IF loop0_eof THEN
LEAVE loop0;
END IF;

UPDATE customers SET hasOverdueBalance = "F" WHERE customerID = tmp_customerID;


END LOOP loop0;
CLOSE cur0;



END


It all compiles well enough but does not actually update anything when I run it. I get warning 1329 No data - zero rows fetched, selected or processed.


I have probably missed something obvious but just cant see it.The SELECT statement for the cursor return 273 customerIDs so there is definitely data for teh cursor to work with.

J

Options: ReplyQuote


Subject
Views
Written By
Posted
Table Not Updating
2781
April 27, 2016 07:22AM
745
April 27, 2016 08:15AM
930
April 27, 2016 11:56AM
818
April 27, 2016 12:27PM
895
April 27, 2016 12:44PM
891
April 27, 2016 01:35PM
912
April 27, 2016 01:51PM
785
April 27, 2016 01:56PM
969
April 27, 2016 02:29PM


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.