mysql在存储过程中执行拼接的动态sql语句

2019-06-19 作者:计算机教程   |   浏览(126)

www.2003.com,如下代码演示如何在存储过程中执行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

本文由www.2003.com发布于计算机教程,转载请注明出处:mysql在存储过程中执行拼接的动态sql语句

关键词: