CREATE DEFINER=`root`@`localhost` PROCEDURE `p_dc_log`( IN UName VARCHAR(50), IN Description VARCHAR(50), IN PageSize int, IN PageIndex int, OUT TotalCount int ) BEGIN set @QueryWhere = ''; #条件查询 IF LENGTH(UName) > 0 THEN set @QueryWhere = CONCAT(@QueryWhere,' AND UserName = ? '); END IF; IF LENGTH(Description) > 0 THEN set @QueryWhere = CONCAT(@QueryWhere,' AND Description LIKE ''%',Description,'%'' '); END IF; #查询总条数 SELECT @QuerySql := CONCAT('SELECT COUNT(1) INTO @TotalCount FROM dc_log WHERE 1 = 1',@QueryWhere); PREPARE stmt FROM 'SELECT COUNT(1) INTO @TotalCount FROM dc_log WHERE 1 = 1'; EXECUTE stmt; SELECT @TotalCount AS Tcount; SET TotalCount = @TotalCount; END