常用数据库分页代码

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 Server

select top ? * from Cat order by newid()
select top 100 * from Cat order by newid()
从Cat表中随机取出100条记录

你可能感兴趣的:(oracle,sql,mysql,SQL Server,HSQLDB)