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;‘)
结果