mysql 教程 存储过程_MySQL
程序员文章站
2022-03-21 14:46:36
...
bitsCN.com
不过在网上找了一些,发现都有一个特点――就是不能传出总记录数,干脆自己研究吧。终于,算是搞出来了,效率可能不是很好,但是我也觉得不错了。贴代码吧直接:也算是对自己学习mysql的一个记录。
CREATE PROCEDURE p_pageList
(
m_pageNo int ,
m_perPageCnt int ,
m_column varchar(1000) ,
m_table varchar(1000) ,
m_condition varchar(1000),
m_orderBy varchar(200) ,
out m_totalPageCnt int
)
BEGIN
SET @pageCnt = 1; -- 总记录数
SET @limitStart = (m_pageNo - 1)*m_perPageCnt;
SET @limitEnd = m_perPageCnt;
SET @sqlCnt = CONCAT('select count(1) into @pageCnt from ',m_table); -- 这条语句很关键,用来得到总数值
SET @sql = CONCAT('select ',m_column,' from ',m_table);
IF m_condition IS NOT NULL AND m_condition '' THEN
SET @sql = CONCAT(@sql,' where ',m_condition);
SET @sqlCnt = CONCAT(@sqlCnt,' where ',m_condition);
END IF;
IF m_orderBy IS NOT NULL AND m_orderBy '' THEN
SET @sql = CONCAT(@sql,' order by ',m_orderBy);
END IF;
SET @sql = CONCAT(@sql, ' limit ', @limitStart, ',', @limitEnd);
PREPARE s_cnt from @sqlCnt;
EXECUTE s_cnt;
DEALLOCATE PREPARE s_cnt;
SET m_totalPageCnt = @pageCnt;
PREPARE record from @sql;
EXECUTE record;
DEALLOCATE PREPARE record;
END
bitsCN.com
CREATE PROCEDURE p_pageList
(
m_pageNo int ,
m_perPageCnt int ,
m_column varchar(1000) ,
m_table varchar(1000) ,
m_condition varchar(1000),
m_orderBy varchar(200) ,
out m_totalPageCnt int
)
BEGIN
SET @pageCnt = 1; -- 总记录数
SET @limitStart = (m_pageNo - 1)*m_perPageCnt;
SET @limitEnd = m_perPageCnt;
SET @sqlCnt = CONCAT('select count(1) into @pageCnt from ',m_table); -- 这条语句很关键,用来得到总数值
SET @sql = CONCAT('select ',m_column,' from ',m_table);
IF m_condition IS NOT NULL AND m_condition '' THEN
SET @sql = CONCAT(@sql,' where ',m_condition);
SET @sqlCnt = CONCAT(@sqlCnt,' where ',m_condition);
END IF;
IF m_orderBy IS NOT NULL AND m_orderBy '' THEN
SET @sql = CONCAT(@sql,' order by ',m_orderBy);
END IF;
SET @sql = CONCAT(@sql, ' limit ', @limitStart, ',', @limitEnd);
PREPARE s_cnt from @sqlCnt;
EXECUTE s_cnt;
DEALLOCATE PREPARE s_cnt;
SET m_totalPageCnt = @pageCnt;
PREPARE record from @sql;
EXECUTE record;
DEALLOCATE PREPARE record;
END
bitsCN.com
推荐阅读
-
PHP,Mysql-根据一个给定经纬度的点,进行附近地点查询–合理利用算法,效率提高2125倍,mysql-2125倍_PHP教程
-
MySQL的存储引擎介绍与操作
-
每日分析日志文件并将结果入库到MySQL的实现过程讲解
-
怎么现在写MYSQL数据库 都在用存储过程了。ecshop phpcms等等 这些好像都没有用给
-
linux php mysql数据库备份实现代码_PHP教程
-
PHP MySQL开发中的一些经验_PHP教程
-
MySQL研发中心成立发布会会后访问整理 (1)(2)_PHP教程
-
读书笔记-MySQL存储过程-存储函数_MySQL
-
PHP-MySQL教程归纳总结
-
测试PHP连接MYSQL成功与否的代码_PHP教程