Author: MaverickBlog:Http://blog.csdn.net/zhaohuabing reprinted please indicate the source
Oracle
Create or replace procedure page (
P_num integer,
P_size integer,
Condition clob,
Table_name varchar,
P_rowset out sys_refcursor)
As
Begin
Open p_rowset
'Select *
From (
Select rownum R, T1 .*
From (
Select '| table_name |'. * from' | table_name |''
| Condition | 'order by happentime DESC) T1
Where rownum <= '| p_size * p_num |') T2
Where t2.r> '| p_size * (p_num-1 );
End page;
Ii. MSSQL
Create procedure page
@ P_num int,
@ P_size int,
@ Condition text,
@ Table_name nvarchar (100 ),
@ Current_page_size int
As
If @ p_num = 1
Execute ('select top '+ @ p_size +' * from '+ @ table_name + ''+ @ condition + 'order by happentime DESC ')
Else
If @ current_page_size! = @ P_size
Execute ('select * from (
Select top '+ @ current_page_size +' * from' + @ table_name + ''+ @ condition + 'order by happentime
) As t order by happentime DESC ')
Else
Begin
Declare @ TMP int
Set @ TMP = @ p_size * @ p_num
Execute ('select * from (
Select top '+ @ p_size +' * from (
Select top '+ @ TMP +' * from '+ @ table_name + ''+ @ condition + 'order by happentime DESC
) As T1 order by happentime
) As T2 order by happentime DESC ')
End
Go
Sybase 3
Create procedure page
@ P_num int,
@ P_size int,
@ Condition nvarchar (3000 ),
@ Table_name nvarchar (100 ),
@ Current_p_size int
As
Declare @ str_p_size varchar (20 ),
@ Str_tmp varchar (20 ),
@ Str_current_p_size varchar (20 ),
@ I _rowcount int
Begin
Select @ str_tmp = cast (@ p_size * @ p_num as varchar (20 ))
Select @ str_p_size = cast (@ p_size as varchar (20 ))
Select @ str_current_p_size = cast (@ current_p_size as varchar (20 ))
If @ p_num = 1
Begin
Set @ I _rowcount = @ p_size * @ p_num
Set rowcount @ I _rowcount
Execute ('select * from' + @ table_name + ''+ @ condition + 'order by happentime DESC ')
End
Else
If @ current_p_size! = @ P_size
Begin
Set rowcount @ current_p_size
Execute ('select * into # temp from '+ @ table_name + ''+ @ condition + 'order by happentime
Select * from # temp order by happentime DESC ')
End
Else
Begin
Set @ I _rowcount = @ p_size * @ p_num
Set rowcount @ I _rowcount
Execute ('select * into # temp1 from '+ @ table_name + ''+ @ condition + 'order by happentime DESC
Select top '+ @ str_p_size +' * into # temp2 from # temp1 order by happentime
Select * from # temp2 order by happentime DESC ')
End
End