MySQL Forums
Forum List  »  Stored Procedures

Case statement inside a cursor loop in stored procedure
Posted by: Aditya Ponnapalli
Date: October 20, 2012 03:47AM

The following doesn't work. I've tried Case stmt, individual case stmts and this. I can't find any documentation or info around this. Help is appreciated.

Thanks!


DELIMITER $$

CREATE DEFINER=`root`@`localhost` PROCEDURE `NumberOfEmployeesLookupProcess`()
Begin
DECLARE empcount int;
DECLARE iDone INT DEFAULT 0;

Declare employee_counter Cursor for
Select distinct employee_count
from employers_to_migrate order by employee_count;

DECLARE CONTINUE HANDLER FOR NOT FOUND SET iDone = 1;

Open employee_counter;

iteratorLoop: Loop

Fetch next from employee_counter
Into empcount;

IF 1 = iDone then
LEAVE iteratorLoop;
End if;

if empcount=0 then update employers_to_migrate set number_of_employees = "1-10";
elseif empcount=20 then update employers_to_migrate set number_of_employees = "10-100";
else update employers_to_migrate set number_of_employees = "other";
end if;

End Loop;

Close employee_counter;

End

Options: ReplyQuote


Subject
Views
Written By
Posted
Case statement inside a cursor loop in stored procedure
5000
October 20, 2012 03:47AM


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.