六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 260|回复: 0

(转)常用数据库分页代码

[复制链接]

升级  12%

16

主题

16

主题

16

主题

秀才

Rank: 2

积分
68
 楼主| 发表于 2013-1-14 23:49:13 | 显示全部楼层 |阅读模式
MySQL
select * from Cat limit ?,?select * from Cat limit 20000,100从Cat表中第20000条开始取出100条记录,即记录号为20000到20099的记录select * from Cat limit ?select * from Cat limit 100从Cat表中取出记录号为1到100的记录select * from Cat order by rand() limit ?select * from Cat order by rand() limit 100从Cat表中随机取出100条记录

Oracle
select * from (select *, rownum rownum_ from Cat where rownum <= ?) where rownum_ > ?select * from (select *, rownum rownum_ from Cat where rownum <= 20099) where rownum_ > 19999从Cat表中第20000条开始取出100条记录,即记录号为20000到20099的记录select * from Cat where rownum <= ?select * from Cat where rownum <= 100从Cat表中取出记录号为1到100的记录select * from (select * from Cat order by dbms_random.value) where rownum < ?select * from (select * from Cat order by dbms_random.value) where rownum < 100从Cat表中随机取出100条记录
HSQLDB
select * from Cat limit ? ?select * from Cat limit 20000 100从Cat表中第20000条开始取出100条记录,即记录号为20000到20099的记录select * from Cat top ?select * from Cat top 100从Cat表中取出记录号为1到100的记录SQL Serverselect top ? * from Cat order by newid()select top 100 * from Cat order by newid()从Cat表中随机取出100条记录
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表