翻翻过去那场雪
可以用 CONCAT把查询语言与变量连接起来再执行,参考如下代码。DELIMITER //CREATE PROCEDURE GetItems()BEGINSELECT @total := count(id) FROM items;SET @sql = CONCAT('SELECT id, title FROM items LIMIT 0,', CEIL(@toal/2));PREPARE stmt FROM @sql;EXECUTE stmt;END //DELIMITER ;