Use paging strings in sqlserver and Oracle.

Source: Internet
Author: User
Sqlserver:

Select * from
(
Select top (Pagesize) * From
(
Select top (Pagesize*Pageindex)*
From articles
Order by ID DESC
)
Order by ID ASC
)
Order by ID DESC

ORACLE:

Select * from (
Select rownum num, T1 .*
From table T1 where fast = 0
) Where num> = IntpositionAnd num <= Intendposition

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// ////////////////
In fact, this is also true for SQL Server. However, it is difficult to write SQL statements without the convenience of oracle. In addition, if SQL statements with order by are passed in, it may be a problem sometimes.
Http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/dnaspp/html/pagercontrols. asp
This is officially the case.
Http: // 211.155.226.126: 8090/uploadfile/500wsplit. rar no way. I have no website. I had to make a video. :) Videos occupy a lot of resources. It is faster. The principle can be seen in the explanation of hibernate paging query principle, which is also a product of the future. I forgot who wrote it. Google it. Public String getlimitstring (string SQL ){
Stringbuffer pagingselect = new stringbuffer (100 );
Pagingselect. append ("select * from (select row _. *, rownum _ from (");
Pagingselect. append (SQL );
Pagingselect. append (") Row _ Where rownum <= ?) Where rownum _>? ");
Return pagingselect. tostring ();
} Oracle uses nested 3-layer query statements and rownum to implement paging. This is the fastest way in Oracle. If rownum is only one or two-layer query statements, order by is not supported. That is, based on this.
Actual code private void page_load (Object sender, system. eventargs E)
{
If (! Page. ispostback)
{
Tzhpager1.selectcommand = "select ID, age, sex, memo from test ";
Tzhpager1.connectionstring = "User ID = test500; Password = test500; Data Source = db01 ";
Tzhpager1.currentpageindex = 0;
Tzhpager1.databind ();
}
} Is to throw an arbitrary legal SQL statement, generate a new SQL statement, and then execute it. No stored procedure is used. The index of the table in the database is not created. :) Sqlserver ============================================== ================================
Select * from
(Select top itemsperpage * from
(Select top itemsperpage * currentpageindex * from
(Selectcommand) as t0
Order by sortfield ASC) as T1
Order by sortfield DESC) as T2
Order by sortfield
Here is my test. But it seems inconvenient.
------ Select *
From (select top 20 *
From (select top 20 *
From (select top 20 employees. lastname, employees. firstname,
Orders. orderid
From employees inner join
Orders on
Employees. employeeid = orders. employeeid
Order by orders. orderid) t0
Order by orderid) T1
Order by orderid DESC) derivedtbl
Order by orderid ------------------------------------
Select *
From (select top 20 *
From (select Top 40 *
From (select top 20 employees. lastname, employees. firstname,
Sum (orders. Freight) as summ
From employees inner join
Orders on
Employees. employeeid = orders. employeeid
Group by employees. lastname, employees. firstname
Order by employees. lastname, employees. firstname) t0
Order by lastname, firstname) T1
Order by lastname, firstname DESC) T2
Order by lastname, firstname

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.