mysql script for dynamic running sql script

CREATE DEFINER=`root`@`localhost` PROCEDURE `getData`(deviceName varchar(45),startTime datetime,endTime datetime)
BEGIN

set @s1 = concat('SELECT * FROM ', deviceName , ' where view_time between ''' , startTime , ''' and ''' , endTime ,''' ;');
prepare s2 from @s1;
execute s2;
    
END
原文地址:https://www.cnblogs.com/sskset/p/3326443.html