mysql 存储过程,执行动态sql语句

DROP PROCEDURE IF EXISTS sp_name;
create procedure sp_name()
begin

declare _userid,_id,no_rs int;


declare sitelist  CURSOR  for select userid,id from eop_site ;

DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_rs=1; 

open sitelist;

repeat
fetch sitelist  into _userid,_id;
set @updatesql  =CONCAT('update  es_menu_', _userid, '_',_id ,' set title =\'易族易站\' where title=\'访问易邦\' ' );
PREPARE sqltext from @updatesql;
execute  sqltext;
UNTIL no_rs 
end repeat ;

CLOSE sitelist;
SET no_rs=0;

end
 

你可能感兴趣的:(sql,mysql)