MySQL Forums
Forum List  »  Stored Procedures

Re: help with procedure and tablename
Posted by: Roland Bouman
Date: February 12, 2006 03:16AM

Why? Jay's sugggestion is totally correct, use the PREPARE syntax. This should work fine:

drop procedure curdemo;
delimiter //
CREATE PROCEDURE curdemo()
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE id_memberx int (16);
DECLARE tabla int (3);
DECLARE cur1 CURSOR FOR SELECT `ID_MEMBER`,FLOOR(`ID_MEMBER`/10000) FROM `yabbse_members` ORDER BY `memberName` LIMIT 100;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;

OPEN cur1;

myloop: LOOP
FETCH cur1 INTO id_memberx,tabla;
if done = 1 then
leave myloop;
end if;
SELECT memberName FROM `yabbse_members` WHERE `ID_MEMBER`=id_memberx;
SELECT id_memberx,CONCAT('tabla ',tabla);

@stmt := concat(
'INSERT INTO '
, cur1.tabla
, ' SELECT * FROM `yabbse_members` WHERE `ID_MEMBER`=id_memberx'
)
PREPARE stmt FROM @stmt;
EXECUTE stmt;
DEALLOCATE stmt;

end loop;

CLOSE cur1;
END
//
delimiter ;

Options: ReplyQuote


Subject
Views
Written By
Posted
2195
February 10, 2006 02:45AM
1455
February 10, 2006 06:12AM
1309
February 10, 2006 11:26AM
1938
February 10, 2006 01:38PM
1344
February 10, 2006 01:51PM
1364
February 10, 2006 04:25PM
1319
February 12, 2006 01:03AM
Re: help with procedure and tablename
1375
February 12, 2006 03:16AM


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.