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

 

你可能感兴趣的:(dynamic)