zoukankan      html  css  js  c++  java
  • MySQL分页存储过程

    CREATE PROCEDURE ProcPage(in tableName varchar(20),#表名  in showField varchar(100),#要显示的列名  in whereText varchar(500),#where条件(只需要写where后面的语句)  in orderText varchar(500),#排序条件(只需要写order by后面的语句) in pageSize int,#每一页显示的记录数  in pageIndex int,#当前页  out dataCount int#总记录数  )  

    BEGIN  

    if (pageSize<1)then

     set pageSize=20;  

    end if;  

    if (pageIndex < 1)then  

    set pageIndex = 1;

     end if;  

    if(LENGTH(whereText)>0)then  

    set whereText=CONCAT(' where 1=1 ',whereText);  

    end if;  

    if(LENGTH(orderText)>0)then  

    set orderText = CONCAT(' ORDER BY ',orderText);  

    end if;  

    set @strsql = CONCAT('select ',showField,' from ',tableName,' ',whereText,' ',orderText,' limit ',pageIndex*pageSize-pageSize,',',pageSize);  

    prepare stmtsql from @strsql;  

    execute stmtsql;  

    deallocate prepare stmtsql;  

    set @strsqlcount=concat('select count(1) as count into @datacount from ',tableName,'',whereText);  

    prepare stmtsqlcount from @strsqlcount;  

    execute stmtsqlcount;  

    deallocate prepare stmtsqlcount;  

    set datacount=@datacount;  

    END;  

  • 相关阅读:
    个人博客设计:创建Sql数据库操作类。
    文件 md5 查看 命令
    https 理解
    ie8、9 post 跨域
    tomcat https
    wamp 初始化 修改mysql密码
    面试-Android之java基础
    apktool.bat
    面试------Android 版本之前的差异(常见,欢迎补充)。
    ubuntu kylin 设置 wifi
  • 原文地址:https://www.cnblogs.com/wlming/p/7676489.html
Copyright © 2011-2022 走看看