The project needs to use the Sybase database paging function, to do all kinds of methods are not successful, and finally use the following stored procedures to successfully implement the function, record the memo.
CREATE PROCEDUREJsp_query_page@sql varchar( -),@start int,@pageSize int as begin Declare @ipage int Declare @rcount int Declare @execsql varchar( -) Declare @sql1 varchar( -) Declare @t int,@p int,@n int,@l int begin Set @sql1=@sql Set @n=0 Set @l=0 Set @t=charindex('Select',Lower(@sql)) Set @sql=substring(@sql,@t+7, Char_length (@sql)-7) Set @n=@n+1 Set @l=@l+7 while(@n!=0) begin Set @t=charindex('Select',Lower(@sql)) Set @p=charindex(' from',Lower(@sql)) if((@t<@p) and(@t!=0)) begin Set @sql=substring(@sql,@t+7, Char_length (@sql)-7) Set @n=@n+1 Set @l=@l+6+@t End Else begin Set @sql=substring(@sql,@p+5, Char_length (@sql)-5) Set @n=@n-1 Set @l=@l+4+@p End End Set @execsql = substring(@sql1,1,@l-5)+', Sybid=identity () into #temp'+substring(@sql1,@l-4, Char_length (@sql1)-@l+5) Select @rcount=@start + @pageSize Set RowCount @rcount Set @execsql = @execsql || 'SELECT * from #temp where sybid>' || Convert(varchar,@start)|| 'and sybid <=' || Convert(varchar,@rcount) Print @execsql Execute(@execsql) Set RowCount 0 End End
Paging functionality for Sybase databases