oracle分页查询sql原理与语句
很多朋友使用多了mysql limit进行分页到了oracle中就不知道如何写分页了,其实oracle分页与mssql分页很像的,下面我来给大家介绍oracle分页语句。
很多朋友使用多了mysql limit进行分页到了oracle中就不知道如何写分页了,其实oracle分页与mssql分页很像的,下面我来给大家介绍oracle分页语句。最简单使用方法
代码如下 | 复制代码 |
t2.* |
小于最大的,大于最小的,就是你需要的条数.如果你取40-50条之间的
查询格式:
代码如下 | 复制代码 |
SELECT * FROM |
其中最内层的查询SELECT * FROM TABLE_NAME表示不进行翻页的原始查询语句。ROWNUM = 21控制分页查询的每页的范围。
上面给出的这个分页查询语句,在大多数情况拥有较高的效率。分页的目的就是控制输出结果集大小,将结果尽快的返回。在上面的分页查询语句中,这种考虑主要体现在WHERE ROWNUM
选择第21到40条记录存在两种方法,一种是上面例子中展示的在查询的第二层通过ROWNUM
代码如下 | 复制代码 |
SELECT * FROM ( |
后来发现数据越大就查询越慢了,后来得出一些测试结果分享给大家。
--1:无ORDER BY排序的写法。(效率最高)
--(经过测试,此方法成本最低,只嵌套一层,速度最快!即使查询的数据量再大,也几乎不受影响,速度依然!)
代码如下 | 复制代码 |
SELECT * FROM (Select ROWNUM AS ROWNO, T.* from k_task T where Flight_date between to_date('20060501', 'yyyymmdd') and to_date('20060731', 'yyyymmdd') AND ROWNUM WHERE TABLE_ALIAS.ROWNO >= 10; |
--2:有ORDER BY排序的写法。(效率最高)
--(经过测试,此方法随着查询范围的扩大,速度也会越来越慢哦!)
代码如下 | 复制代码 |
SELECT * FROM (SELECT TT.*, ROWNUM AS ROWNO FROM (Select t.* from k_task T where flight_date between to_date('20060501', 'yyyymmdd') and to_date('20060531', 'yyyymmdd') ORDER BY FACT_UP_TIME, flight_no) TT WHERE ROWNUM where TABLE_ALIAS.rowno >= 10; |
--3:无ORDER BY排序的写法。(建议使用方法1代替)
--(此方法随着查询数据量的扩张,速度会越来越慢哦!)
代码如下 | 复制代码 |
SELECT * FROM (Select ROWNUM AS ROWNO, T.* from k_task T where Flight_date between to_date('20060501', 'yyyymmdd') and to_date('20060731', 'yyyymmdd')) TABLE_ALIAS WHERE TABLE_ALIAS.ROWNO AND TABLE_ALIAS.ROWNO >= 10; --TABLE_ALIAS.ROWNO between 10 and 100; |
--4:有ORDER BY排序的写法.(建议使用方法2代替)
--(此方法随着查询范围的扩大,速度会越来越慢哦!)
代码如下 | 复制代码 |
SELECT * FROM (SELECT TT.*, ROWNUM AS ROWNO FROM (Select * from k_task T where flight_date between to_date('20060501', 'yyyymmdd') and to_date('20060531', 'yyyymmdd') ORDER BY FACT_UP_TIME, flight_no) TT) TABLE_ALIAS where TABLE_ALIAS.rowno BETWEEN 10 AND 20; |
--5另类语法。(有ORDER BY写法)
--(语法风格与传统的SQL语法不同,不方便阅读与理解,为规范与统一标准,不推荐使用。)
代码如下 | 复制代码 |
With partdata as( SELECT ROWNUM AS ROWNO, TT.* FROM (Select * from k_task T where flight_date between to_date('20060501', 'yyyymmdd') and to_date('20060531', 'yyyymmdd') ORDER BY FACT_UP_TIME, flight_no) TT WHERE ROWNUM Select * from partdata where rowno >= 10; |
--6另类语法 。(无ORDER BY写法)
代码如下 | 复制代码 |
With partdata as( |

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use PHP database connection to implement paging query. When developing web applications, it often involves the need to query the database and perform paging display. As a commonly used server-side scripting language, PHP has powerful database connection functions and can easily implement paging queries. This article will introduce in detail how to use PHP database connection to implement paging query, and attach corresponding code examples. Prepare the database Before we start, we need to prepare a database containing the data to be queried. Here we take the MySQL database as an example,

PHP and PDO: How to query and display data in pages When developing web applications, querying and displaying data in pages is a very common requirement. Through paging, we can display a certain amount of data at a time, improving page loading speed and user experience. In PHP, the functions of paging query and display of data can be easily realized using the PHP Data Object (PDO) library. This article will introduce how to use PDO in PHP to query and display data by page, and provide corresponding code examples. 1. Create database and data tables

With the rapid development of the Internet, data processing has become an important skill in enterprise application development. MySQL database is often one of the most commonly used data stores in many applications. In MySQL, data paging query is a common data retrieval operation. This article will introduce how to use Go language to implement high-performance MySQL data paging query. 1. What is data paging query? Data paging query is a commonly used data retrieval technology, which allows users to browse only a small amount of data on a page without loading it all at once.

With the rapid development of the Internet, the development of web applications is becoming more and more complex. And paging query is one of the common functions in web applications. ThinkPHP6 is a web framework that helps developers develop applications quickly. In this article, we will discuss how to perform paginated queries using MySQL in ThinkPHP6. First, we need to create the database in ThinkPHP6. The statement to create a database in MySQL is as follows: CREATEDATABASE

Overview of how PHP uses MongoDB for paginated queries: MongoDB is a non-relational database often used to store large amounts of document data, while PHP is a popular server-side scripting language. In this article, we will introduce how to use PHP to connect to MongoDB and implement paging query function. Step 1: Install the MongoDB extension. To interact with MongoDB in PHP, you need to install the MongoDB extension. The MongoDB extension can be installed with the following command: p

Paging query techniques for PHP and Oracle database When developing a dynamic web page, if you need to display a large amount of data, you need to perform paging query. Paginated query is a technique that divides data into smaller pages so that users can browse and navigate easily. In this article, we will discuss how to implement paginated queries using PHP and Oracle database, and provide relevant code examples. 1. Preparation Before starting, we need to make sure that we have installed and configured PHP and Oracle database. If still

Overview of how to use thinkorm to easily implement paging query function: When developing a website or application, it is often necessary to perform paging query on the data in the database in order to display part of the data on the page and provide page turning function. This article will introduce how to use the thinkorm framework to easily implement the paging query function, and provide relevant code examples. Step 1: Install thinkorm First, you need to install the thinkorm framework in the project. You can use the following command to install it: composerrequi

In modern applications, most data needs to be displayed in pages. When applications need to process large amounts of data, this puts pressure on servers and databases, causing queries to take longer. Mysql is currently one of the most popular relational databases. This article will discuss how to optimize the performance of Mysql paging queries. Principle of paging Before starting optimization, we must first understand the principle of paging. The main principle of paging query is to divide the table data into several pages, and then query the data one by one. For example, if we need to
