MySQL Forums
Forum List  »  Stored Procedures

Re: Stored Procedures Read error
Posted by: Andrew Gilfrin
Date: April 08, 2005 10:28AM

OK try something like this, it's not as efficient as using the single update but it is a solution. Perhaps you could raise the original issue as a bug.


CREATE PROCEDURE `pers`.`UpdateDeptName`(IN p_emp_name VARCHAR(30))
BEGIN

DECLARE l_dept_name VARCHAR(30);
DECLARE l_emp_id, l_dept_id, l_loop_end INT default 0;

DECLARE emp_updates CURSOR FOR SELECT emp_id, dept_id FROM emps WHERE emp_name = p_emp_name;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' set l_loop_end = 1;

OPEN emp_updates;

REPEAT

FETCH emp_updates INTO l_emp_id, l_dept_id;

IF NOT l_loop_end THEN
SELECT description INTO l_dept_name FROM dept WHERE dept_id = l_dept_id;

UPDATE emps SET dept_name = l_dept_name WHERE emp_id = l_emp_id;
END IF;

UNTIL l_loop_end END REPEAT;

END

Andrew Gilfrin
------------------
http://gilfster.blogspot.com
My MySQL related Blog

http://www.mysqldevelopment.com
MySQL Stored Procedure,Trigger, View.... (Just about most things these days) Information

Options: ReplyQuote


Subject
Views
Written By
Posted
3387
April 08, 2005 07:05AM
2218
April 08, 2005 09:53AM
Re: Stored Procedures Read error
2384
April 08, 2005 10:28AM


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.