惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V2EX - 技术
V2EX - 技术
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
GbyAI
GbyAI
aimingoo的专栏
aimingoo的专栏
腾讯CDC
C
CERT Recently Published Vulnerability Notes
J
Java Code Geeks
WordPress大学
WordPress大学
博客园 - Franky
V
Vulnerabilities – Threatpost
小众软件
小众软件
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
有赞技术团队
有赞技术团队
The Hacker News
The Hacker News
T
The Blog of Author Tim Ferriss
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Martin Fowler
Martin Fowler
Webroot Blog
Webroot Blog
Attack and Defense Labs
Attack and Defense Labs
Google Online Security Blog
Google Online Security Blog
S
Securelist
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Troy Hunt's Blog
Scott Helme
Scott Helme
Project Zero
Project Zero
T
Tailwind CSS Blog
The Register - Security
The Register - Security
A
About on SuperTechFans
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
The GitHub Blog
The GitHub Blog
Security Latest
Security Latest
L
LangChain Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
H
Hackread – Cybersecurity News, Data Breaches, AI and More
大猫的无限游戏
大猫的无限游戏
Cloudbric
Cloudbric
S
Security Affairs
博客园 - 叶小钗
Microsoft Security Blog
Microsoft Security Blog
H
Heimdal Security Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
PCI Perspectives
PCI Perspectives
The Cloudflare Blog
Last Week in AI
Last Week in AI
阮一峰的网络日志
阮一峰的网络日志
AI
AI

博客园 - 落木

PowerDesigner中NAME和COMMENT的互相转换,需要执行语句 获取网站根目录的urli源代码 - 落木 - 博客园 Control的Invoke和BeginInvoke 扩大范围的多条件查询 用.net的GetCallbackEventReference函数来实现dropDownList联动的ajax效果 处理SQLSERVER死锁(转载) 调用DirectX进行简单的多媒体编程系列(四) 调用DirectX进行简单的多媒体编程系列(三) 调用DirectX进行简单的多媒体编程系列(二) 调用DirectX进行简单的多媒体编程系列(一) mysql想说爱你不容易啊,从mssql迁移到mysql时,几乎所有的存储过程都得改,语法相差很大,累人!! 自己写的sqlserver和mysql的行转列通用存储过程 MSSQL优化文章 C#中编写sqlserver中自定义函数,实现复杂报表 Ajax使用Post方式提交到.aspx页面交互的例子 核单台帐表(存储过程) 清欠率(存储过程) ExtJS中的面向对象设计,组件化编程思想 - 落木 - 博客园 ExtJS中如何扩展自定义的类
数据库分页算法
落木 · 2009-09-25 · via 博客园 - 落木

 1一、mssql的实现:
 2/*----------------------------------------------------------------------------------
 3 * description: 数据分页存储过程
 4 * author:  LiLF
 5 * date:  2009-9-25
 6---------------------------------------------------------------------------------*/

 7
 8ALTER  procedure [dbo].[ExecSqlGetOnePage]
 9@sqlstr varchar(8000), 
10@currentpage int
11@pagesize int 
12as
13set nocount on
14declare @sumPageCount int 
15declare @P1 int
16 @rowcount int
17exec sp_cursoropen @P1 output,@sqlstr,@scrollopt=1,@ccopt=1,@rowcount=@rowcount output
18set @sumPageCount =ceiling(1.0*@rowcount/@pagesize)
19select @sumPageCount as 总页数
20select @rowcount as 记录总数
21
22            if (@currentpage>@sumPageCount)
23                set @currentpage = @sumPageCount
24            if (@currentpage < 1)
25                set @currentpage = 1
26
27set @currentpage=(@currentpage-1)*@pagesize+1
28exec sp_cursorfetch @P1,16,@currentpage,@pagesize 
29exec sp_cursorclose @P1
30
31
32二、mysql的实现:
33/*----------------------------------------------------------------------------------
34 * description: 数据分页存储过程
35 * author:  LiLF
36 * date:  2009-9-25
37---------------------------------------------------------------------------------*/

38#===drop procedure===============================
39DROP PROCEDURE IF EXISTS ExecSqlGetOnePage;
40#===create procedure========================
41CREATE DEFINER=`root`@`localhost` PROCEDURE `ExecSqlGetOnePage`(
42    /*query string*/
43 $sqlstr varchar(8000),
44    /*Page index*/
45    $pageIndex int,
46    /*Page Size*/
47    $pageSize int 
48  )
49BEGIN  
50
51 DECLARE $sumPageCount int;
52    #===return a empty table======
57    
58    set @rowcount=0;
59    set @sqlcounts=concat('select COUNT(*) into @rowcount from (',$sqlstr,') as a');
60    PREPARE stmt1 FROM @sqlcounts;  
61    EXECUTE stmt1;
62    DEALLOCATE PREPARE stmt1;
63 
64    set $sumPageCount=ceiling(1.0*@rowcount/$pagesize);
65     #====return total pages======
66    select $sumPageCount as 'totalPages';
67    #====return total records=====
68 select @rowcount as 'totalRows';
69
70    if ($pageIndex>$sumPageCount) THEN
71        set $pageIndex = $sumPageCount;
72    end if;
73    if ($pageIndex < 1then
74        set $pageIndex = 1;
75    end if;
76    #====return current page records=====       
77 set @strSQL=concat($sqlstr,' LIMIT  ',($pageIndex-1)*$pageSize,',',$pageSize);   
78    PREPARE stmt1 FROM @strSQL;  
79    EXECUTE stmt1;
80    DEALLOCATE PREPARE stmt1;
81END;
82#======invork procedure===================
83call ExecSqlGetOnePage('select * from system_framework',3,5);
84