zoukankan      html  css  js  c++  java
  • 使用数据库存储过程完成一个简单分页

    --存储过程、row_number完成分页
    if (object_id('pro_page', 'P') is not null)
    drop proc proc_cursor
    go
    create proc pro_page
    @startIndex int,
    @endIndex int
    as
    select count(*) from product
    ;
    select * from (
    select row_number() over(order by pid) as rowId, * from product
    ) temp
    where temp.rowId between @startIndex and @endIndex
    go
    --drop proc pro_page
    exec pro_page 1, 4
    --
    --分页存储过程
    if (object_id('pro_page', 'P') is not null)
    drop proc pro_stu
    go
    create procedure pro_stu(
    @pageIndex int,
    @pageSize int
    )
    as
    declare @startRow int, @endRow int
    set @startRow = (@pageIndex - 1) * @pageSize +1
    set @endRow = @startRow + @pageSize -1
    select * from (
    select *, row_number() over (order by id asc) as number from student
    ) t
    where t.number between @startRow and @endRow;

    exec pro_stu 2, 2;

     

  • 相关阅读:
    数据库基础
    Junit单元测试、反射与注解
    Stream流
    Java IO所用类
    字符集
    Lambda表达式
    【jdk1.8源码分析】LinkedHashMap
    线性表
    【jdk1.8源码分析】ArrayList
    java学习血泪史
  • 原文地址:https://www.cnblogs.com/xujie520/p/5411287.html
Copyright © 2011-2022 走看看