支持批量执行的mysql存储过程

CREATE PROCEDURE `execute_batch_sql`(sqlstr varchar(5000))
BEGIN
        set @string=sqlstr; 
    set @current_str= SUBSTR(@string,1,LOCATE(";",@string)); 
        WHILE length(@current_str)>0 DO           
          PREPARE sql_sentence FROM @current_str;
            EXECUTE sql_sentence ;
            DEALLOCATE PREPARE sql_sentence;  
          set @string= SUBSTR(@string, LOCATE(";",@string)+1 ); 
            set @current_str= SUBSTR(@string,1,LOCATE(";",@string)); 
        END WHILE;  
END

调用方法

call execute_batch_sql(select 1;select 2;)

结果

支持批量执行的mysql存储过程

支持批量执行的mysql存储过程

上一篇:sql exec sp_executesql执行动态语句


下一篇:mybatis动态sql(常用)