mysql数据库存储过程学习实现分页

http://blog.csdn.net/rhljiayou/article/details/6977143


DELIMITER $$


DROP PROCEDURE IF EXISTS `paging`$$


CREATE
    /*[DEFINER = { user | CURRENT_USER }]*/
    PROCEDURE `test`.`paging`(IN NAME VARCHAR(1024),IN FIELDS VARCHAR(1024),IN size  INT,IN nowpage INT)
   
    BEGIN
DECLARE begin_row INT DEFAULT 0;
DECLARE limit_string CHAR(64); 
SET begin_row=(nowpage-1)*size;
SET limit_string=CONCAT(' limit ',begin_row,',',size);
SET @result=CONCAT('select ',FIELDS,' from ',NAME,' ',limit_string);
PREPARE result_stmt FROM @result;
EXECUTE result_stmt; 
DEALLOCATE PREPARE result_stmt;


    END$$


DELIMITER ;

你可能感兴趣的:(mysql)