mysql 自定义函数动态查询数据

CREATE DEFINER=`root`@`%` PROCEDURE `query_table`(in tableName varchar(200),in counts int(11))
BEGIN

set @script=concat('select * from ',tableName , ' order by id desc limit 0,',counts);

prepare stmt from @script;

execute stmt;

DEALLOCATE PREPARE stmt;

END

 

posted @ 2022-05-17 19:49  mild  阅读(416)  评论(0编辑  收藏  举报