How do I return a query result between the specified number of lines?

Source: Internet
Author: User
Tags exit return


How do I return a query result between the specified number of lines?


How to return the query results between the specified number of rows to implement Web record paging, there are many methods in Oracle, there are only 4 of them listed here, I hope to help you, you can choose the following script according to different needs

1 Select ... where rownum < minus select ... where rownum < 30
This method is used because of the minus operator, so the speed is affected.

2)
SELECT results.* from
(SELECT t2.*, rownum RowNumber from
(SELECT t.* from mv_table t WHERE order by col1) T2) Results
WHERE Results.rownumber BETWEEN by col1

This method is seen from a forum and has not been personally tested

3)
Define cursor x, 2.fetch x a,b,c; Loop ... end loop;
It uses two loop variables and a flag variable, representing the current number of records, the first page, and page one.
ps
J:=to_number (KAFYF);
I:=1;
Open CX;
Loop fetch CX into COL1,COL2,COL3,COL4,COL5,COL6;
If Cx%notfound then exit; End If;
If I>=j Then
Htp.tablerowopen;
Htp.tabledata (col1);
Htp.tabledata (col2);
Htp.tabledata (COL4);
Htp.tabledata (COL5);
Htp.tabledata (COL6);
Htp.tabledata (COL3);
Htp.tablerowclose;
i:=i+1;
If I=j+10 then l:=1; Exit End If;
else i:=i+1;
End If;
End Loop;
Close x;

The method was written by a netizen named ' Miao ', who used the Owa_util package in Oracle Web2kit.

4 How can one page forward and backwards through a table?
Externalize RowNum by implementing queries like this:

SELECT ...
From (SELECT rownum rnum, ... From ...)
WHERE rnum Between:low And:high and RowNum < (: High:low + 1);

Where:low And:high are dynamically generated values depending on which result page the user
is viewing. Typically, they are used to show "Next matches", "Previous matches" links at the
Bottom of each page.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.