mysql表名作为参数传入存储过程
有以下存储过程:
CREATE DEFINER=`root`@`localhost` PROCEDURE `P_HoverTreePages`( IN `TableName` VARCHAR(200), IN `FieldList` VARCHAR(2000) , IN `PrimaryKey` VARCHAR(100), IN `Where` VARCHAR(2000), IN `Order` VARCHAR(1000), IN `SortType` INT, IN `RecorderCount` INT, IN `PageSize` INT, IN `PageIndex` INT, OUT `TotalCount` INT, OUT `TotalPageCount` INT ) LANGUAGE SQL NOT DETERMINISTIC CONTAINS SQL SQL SECURITY DEFINER COMMENT 'fenye' BEGIN set @sqlStr = CONCAT('select * from ',TableName); prepare sqlStr from @sqlStr; execute sqlStr; END
有这个表:
调用存储过程:
CALL `P_HoverTreePages`('t_hovertreenote', 'h', 'h', 'h', 'h', '1', '1', '2', '1', @hh, @yy)
结果: