mysql数据库存储过程带预处理sql的模板
来源:互联网 发布:js文件调用java代码 编辑:程序博客网 时间:2024/05/20 22:32
CREATE DEFINER=`root`@`%` PROCEDURE `getMaSalemenPLPercentageRecordByPage`(IN `pageSize` int,IN `pageNo` int,IN `companyID` long,IN `apixID` long,IN `userID` long,IN `beginTime` varchar(30),IN `endTime` varchar(30))
BEGIN
#根据日期分组,计算某一页的数据
DECLARE beginS int DEFAULT 0;
DECLARE endS int DEFAULT 10;
DECLARE baseSql VARCHAR(5000) DEFAULT '';
DECLARE totalCount int DEFAULT 0;-- 总条数
DECLARE beginTimePage TIMESTAMP;-- 分页开始时间
DECLARE endTimePage TIMESTAMP;-- 分页结束时间
set beginS=(pageNo-1)*pageSize;
set endS=pageSize;
DROP table if EXISTS baseTable;
set baseSql=CONCAT(baseSql,"create temporary table baseTable select '合计' as total ");
set baseSql=CONCAT(baseSql," from table_a where 1=1 ");
if(companyID is not null and companyID != '' and companyID != 0) then set baseSql=CONCAT(baseSql," AND a.company_id = ",companyID); END if;
if(apixID is not null and apixID != '' and apixID != 0) then set baseSql=CONCAT(baseSql," AND a.apix_id = ",apixID); END if;
if(userID is not null and userID != '' and userID != 0) then set baseSql=CONCAT(baseSql," AND a.user_id = ",userID); END if;
if(beginTime is not null and beginTime != '' ) then set baseSql=CONCAT(baseSql," AND r.query_time >= '",beginTime,"'"); END if;
if(endTime is not null and endTime != '' ) then set baseSql=CONCAT(baseSql," AND r.query_time <= '",date_format(endTime,'%Y-%m-%d 23:59:59'),"'"); END if;
-- select baseSql;
set @baseSql=baseSql; -- 注意很重要,将连成成的字符串赋值给一个变量(可以之前没有定义,但要以@开头)
prepare stmt from @baseSql; -- 预处理需要执行的动态SQL,其中stmt是一个变量
EXECUTE stmt; -- 执行SQL语句
deallocate prepare stmt; -- 释放掉预处理段
from baseTable ;
truncate baseTable;
END
BEGIN
#根据日期分组,计算某一页的数据
DECLARE beginS int DEFAULT 0;
DECLARE endS int DEFAULT 10;
DECLARE baseSql VARCHAR(5000) DEFAULT '';
DECLARE totalCount int DEFAULT 0;-- 总条数
DECLARE beginTimePage TIMESTAMP;-- 分页开始时间
DECLARE endTimePage TIMESTAMP;-- 分页结束时间
set beginS=(pageNo-1)*pageSize;
set endS=pageSize;
DROP table if EXISTS baseTable;
set baseSql=CONCAT(baseSql,"create temporary table baseTable select '合计' as total ");
set baseSql=CONCAT(baseSql," from table_a where 1=1 ");
if(companyID is not null and companyID != '' and companyID != 0) then set baseSql=CONCAT(baseSql," AND a.company_id = ",companyID); END if;
if(apixID is not null and apixID != '' and apixID != 0) then set baseSql=CONCAT(baseSql," AND a.apix_id = ",apixID); END if;
if(userID is not null and userID != '' and userID != 0) then set baseSql=CONCAT(baseSql," AND a.user_id = ",userID); END if;
if(beginTime is not null and beginTime != '' ) then set baseSql=CONCAT(baseSql," AND r.query_time >= '",beginTime,"'"); END if;
if(endTime is not null and endTime != '' ) then set baseSql=CONCAT(baseSql," AND r.query_time <= '",date_format(endTime,'%Y-%m-%d 23:59:59'),"'"); END if;
-- select baseSql;
set @baseSql=baseSql; -- 注意很重要,将连成成的字符串赋值给一个变量(可以之前没有定义,但要以@开头)
prepare stmt from @baseSql; -- 预处理需要执行的动态SQL,其中stmt是一个变量
EXECUTE stmt; -- 执行SQL语句
deallocate prepare stmt; -- 释放掉预处理段
-- 处理好的数据与其他表进行关联等操作
select *from baseTable ;
truncate baseTable;
END
0 0
- mysql数据库存储过程带预处理sql的模板
- mysql数据库存储过程带游标模板
- mysql存储过程预处理(动态sql)
- mysql存储过程 预处理变量
- Sql调试带输出的存储过程
- SQL Server带游标的存储过程
- mysql 的存储过程一定要带()
- mysql 带参数的存储过程
- Mysql创建带参的存储过程
- MYSQL存储过程模板
- MySQL存储过程模板
- 一个MySQL存储过程的模板
- MySql带参数的存储过程编写(动态执行SQL语句)
- MySql带参数的存储过程编写(动态执行SQL语句)
- MySQL数据库中如何新建一个带参数的存储过程procedure
- mysql 函数、存储过、带循环的存储过程
- sql sever和mysql数据库的存储过程转换过程 scope_identity() last_insert_id();
- mysql带参存储过程
- Java 内存模型及GC原理
- PAT 1021
- mysql唯一索引失效原因分析
- 测试使用
- Maven与nexus关系
- mysql数据库存储过程带预处理sql的模板
- CSS三栏式自适应
- QT 简单的写日志功能
- Python+selenium环境搭建
- Java多线程之run()与start()
- 面对需求的处理态度
- 设计模式之--观察者模式(Observer Pattern)(22)
- Linux文本处理之只打印某个域后的内容
- tomcat 7下spring 4.x mvc集成websocket以及sockjs完全参考指南