Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Paging query examples of oracle, mysql and SqlServer databases

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "paging query examples of oracle, mysql and SqlServer databases". In daily operation, I believe many people have doubts about paging query examples of oracle, mysql and SqlServer databases. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "paging query examples of oracle, mysql and SqlServer databases". Next, please follow the editor to study!

MySql:

MySQL database is relatively simple to implement paging and provides LIMIT functions. Generally, you just need to write directly after the SQL statement. The limit clause can be used to limit the amount of data returned by the SELECT statement. It has one or two parameters. If two parameters are given, the first parameter specifies the position of the first row returned in all data, starting with 0 (note that it is not 1), and the second parameter specifies the maximum number of rows returned. For example: select * from table WHERE … LIMIT 10; # returns the first 10 lines select * from table WHERE... LIMIT 0d10; # returns the first 10 lines select * from table WHERE... LIMIT 10d20; # returns 10-20 rows of data

Oracle:

Considering the implementation of paging in mySql, the select * from table name limit starts with the number of records and how many entries are displayed; we can achieve our paging effect.

But there is no limit keyword in oracle, but there is a rownum field

Rownum is a pseudo column, which is the number assigned by the oracle system to each row of the results returned by the query, the first behavior 1, the second behavior 2, and so on.

The first kind:

The copy code is as follows: SELECT * FROM (SELECT A. FROM TABLE_NAME, ROWNUM RN FROM (SELECT * code) A WHERE ROWNUM = 21

The innermost query SELECT * FROM TABLE_NAME represents the original query statement that does not turn the page. ROWNUM = 21 controls the scope of each page of the paging query.

The paging query given above is efficient in most cases. The purpose of paging is to control the size of the output result set and return the results as soon as possible. In the paging query above, this consideration is mainly reflected in WHERE ROWNUM

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report