Home  >  Article  >  Database  >  数据库分页查询

数据库分页查询

WBOY
WBOYOriginal
2016-06-07 16:11:101610browse

1) mysql select * from demowhere1=1 LIMIT 2,3 limit是用来分页的,第一个参数是行号,第二个参数是说有多少行 2) oracle 第一种 SELECT ID, FIELD_NAME,.. . FROM TABLE_NAME WHERE ID IN (SELECT ID FROM (SELECT ROWNUM AS NUMROW, ID FROM TABLE_NAM

1) mysql

	select * from demo
	where
		1=1 LIMIT 2,3

limit是用来分页的,第一个参数是行号,第二个参数是说有多少行

2) oracle

第一种

SELECT ID, FIELD_NAME,.. .
  FROM TABLE_NAME
 WHERE ID IN (SELECT ID
                FROM (SELECT ROWNUM AS NUMROW, ID
                        FROM TABLE_NAME
                       WHERE 条件1
                       ORDER BY 条件2)
               WHERE NUMROW > 80
                 AND NUMROW < 100)
 ORDER BY 条件3;

第二种

SELECT *  
FROM   (SELECT a.*  
              ,rownum rn  
        FROM   (SELECT * FROM table_name) a  
        WHERE  rownum <= 40)  
WHERE  rn >= 21 

如果支持scrollable result,使用ResultSet的absolute方法直接移到查询起点,如果不支持的话,使用循环语句,rs.next一点点的移过去。




Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn