SQL Server的分頁代碼:
SelectByPage
1SET QUOTED_IDENTIFIER ON
2GO
3SET ANSI_NULLS ON
4GO
5
6
7
8ALTER proc SelectByPage(@startRowIndex int,@maximumRows int,@SortBy varchar(50))
9as
10declare @TotalCnt int
11declare @sql varchar(8000)
12begin
13select @TotalCnt = count(*) from sys_user
14
15set @sql = 'select top ' + convert(varchar(20),@maximumRows) + ' * from '
16set @sql = @sql + '('
17set @sql = @sql + ' select top ' + convert(varchar(20),(@TotalCnt-@startRowIndex)) + ' * from sys_user a '
18set @sql = @sql + ' order by a.' + @SortBy + ' desc '
19set @sql = @sql + ') b'
20set @sql = @sql + ' order by b.' + @SortBy
21exec(@sql)
22--print @sql
23end
24
25
26
27GO
28SET QUOTED_IDENTIFIER OFF
29GO
30SET ANSI_NULLS ON
31GO
32
33
Oracle中的分頁方法:
select_by_page
1/**//* Formatted on 2007/04/16 11:16 (Formatter Plus v4.8.8) */
2CREATE OR REPLACE PROCEDURE diswebuser.select_by_page (
3 p_start_page NUMBER,
4 p_page_size NUMBER,
5 p_sort_by VARCHAR2
6)
7AS
8 v_cnt INTEGER;
9 v_sql VARCHAR2 (4000);
10 v_start_index INTEGER;
11 v_end_index
INTEGER;
12BEGIN
13 SELECT COUNT (*)
14 INTO v_cnt
15 FROM side_slope;
16
17 --v_start_index := (p_start_page - 1) * p_page_size + 1;
18 v_start_index := p_start_page + 1;
19 v_end_index := p_start_page + p_page_size;
20 v_sql := v_sql || 'SELECT * ';
21 v_sql := v_sql || ' FROM (SELECT ROWNUM AS row_id, a.* ';
22 v_sql := v_sql || ' FROM side_slope a ';
23 v_sql := v_sql || ' ORDER BY side_slope_id) ';
24 v_sql :=
25 v_sql
26 || ' WHERE row_id BETWEEN '
27 || TO_CHAR (v_start_index)
28 || ' AND '
29 || TO_CHAR (v_end_index)
30 || ' ';
31 v_sql := v_sql || 'ORDER BY side_slope_id ';
32 DBMS_OUTPUT.put_line (v_sql);
33END;
34/
當然在Oracle存儲中返回結構集要使用ref cursor,使用Oracle的朋友一定很清楚,我在這裡就不羅嗦了,那樣寫還得創建包,麻煩^_^,上面只是打印出了sql語句。
還望高手指點