程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Access數據庫 >> Access數據庫入門 >> Oracle、SQL Server、Access數據庫高效果分頁技巧

Oracle、SQL Server、Access數據庫高效果分頁技巧

編輯:Access數據庫入門

  1、SQL Server、Access數據庫

  這都微軟的數據庫,都是一家人,基本的操作都是差不多,常采用如下分頁語句:

  PAGESIZE:每頁顯示的記錄數

  CURRENTPAGE:當前頁號

  數據表的名字是:components

  索引主鍵字是:id

以下是引用片段:
selecttopPAGESIZE*fromcomponentswhereidnotin
(selecttop(PAGESIZE*(CURRENTPAGE-1))
idfromcomponentsorderbyid)orderbyid

  如下列:

以下是引用片段:
selecttop10*fromcomponentswhereidnotin
(selecttop10*10idfromcomponentsorderbyid)
orderbyid

  從101條記錄開始選擇,只選擇前面的10條記錄

  2、Oracle數據庫

  因為Oracle數據庫沒有Top關鍵字,所以這裡就不能夠像微軟的數據據那樣操作,這裡有兩種方法:

  (1)、一種是利用相反的。

  PAGESIZE:每頁顯示的記錄數

  CURRENTPAGE:當前頁號

  數據表的名字是:components

  索引主鍵字是:id

以下是引用片段:
select*fromcomponentswhereidnot
in(selectidfromcomponentswhere
rownum<=(PAGESIZE*(CURRENTPAGE-1)))
andrownum<=PAGESIZEorderbyid;

  如下例:

以下是引用片段:
select*fromcomponentswhereidnotin
(selectidfromcomponentswhererownum<=100)
andrownum<=10orderbyid;

  從101到記錄開始選擇,選擇前面10條。

  (2)、使用minus,即中文的意思就是減去。

以下是引用片段:
select*fromcomponentswhererownum
<=(PAGESIZE*(CURRENTPAGE-1))minus
select*fromcomponentswhererownum
<=(PAGESIZE*(CURRENTPAGE-2));

  如例:select * from components where

以下是引用片段:
rownum<=10minusselect*fromcomponents
whererownum<=5;.

  (3)、一種是利用Oracle的rownum,這個是Oracle查詢自動返回的序號,一般不顯示,但是可以通過select rownum from [表名]看到,注意,它是從1到當前的記錄總數。

以下是引用片段:

select*from(selectrownumtid,components.
*fromcomponentswhererownum<=100)wheretid<=10

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved