MySQL 存储过程,游标,临时表创建
-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$ CREATE DEFINER=`root`@`localhost` PROCEDURE `filter_record_time`(startTime timestamp, endTime timestamp, pointIndex int)
BEGIN
declare _recordtime timestamp;
declare _pointIndex smallint;
declare _value double;
declare _result text;
declare _previoustime timestamp;
DECLARE done INT DEFAULT FALSE; declare fetchSeqCursor cursor for select distinct RecordTime,PointIndex,Value
from flow_record
where recordtime >= startTime
and recordtime < endTime
and pointIndex = pointIndex
and recordtime is not null
order by recordtime; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; create table if not exists filter_record_time_temp(timeFrom timestamp, timeTo timestamp, times int); open fetchSeqCursor; seq_loop:loop
fetch fetchSeqCursor into _recordtime, _pointIndex, _value; IF done THEN
LEAVE seq_loop;
END IF; if _previoustime is null then
if _recordtime <> startTime then
insert into filter_record_time_temp select startTime timefrom, _recordtime timeto,
cast((unix_timestamp(_recordtime) - unix_timestamp(startTime) - 120) / 120 as signed) times;
end if;
else
if unix_timestamp(_previoustime) + 120 < unix_timestamp(_recordtime) then
insert into filter_record_time_temp select _previoustime timefrom, _recordtime timeto,
cast((unix_timestamp(_recordtime) - unix_timestamp(_previoustime) - 120) / 120 as signed) times;
end if;
end if; set _previoustime = _recordtime;
end loop; close fetchSeqCursor; if unix_timestamp(_previoustime) + 120 < unix_timestamp(endTime) then
insert into filter_record_time_temp select _previoustime timefrom, endTime timeto,
cast((unix_timestamp(endTime) - unix_timestamp(_previoustime) - 120) / 120 as signed) times;
end if; select * from filter_record_time_temp; drop table if exists filter_record_time_temp; END
真尼玛烦人,各个数据库sql语法都不一致,写一点东西查半天资料,耽误时间.
MySQL 存储过程,游标,临时表创建的更多相关文章
- MySQL存储过程 游标
MySQL存储过程 游标 如何在存储过程中使用MySQL游标来遍历SELECT语句返回的结果集 MySQL游标简介 要处理存储过程中的结果集,请使用游标.游标允许您迭代查询返回的一组行,并相应地处理 ...
- mysql存储过程游标嵌套循环
自己写的一个mysql存储过程如下: BEGIN DECLARE _did bigint(20);DECLARE _count int;DECLARE s1 int;DECLARE cur_1 CUR ...
- mysql 存储过程、视图---创建、调用、删除
之前一直用的是Sql Server数据库,最近偶然机会接触到mysql.这里总结了关于mysql 存储过程.视图的“创建.调用.删除”示例 ============================== ...
- mysql存储过程游标加计划任务事件调度器
存储过程加事件调度器 -- 存储过程 (多个)游标的使用 临时表的使用(让执行时间从一个小时降低到5分钟)DELIMITER $$ DROP PROCEDURE IF EXISTS `eval_cal ...
- 菜鸟使用MySQL存储过程and临时表,供新手参考,请高手斧正
因为公司最近的一个项目,第一次用到了MySQL(5.10版本),之前听传说MySQL很厉害的样子,因为开源而神奇,但是现在用起来, 感觉并不好啊!我知道是我水平太down,呜呜呜,请各路神仙略施小技, ...
- MySQL 存储过程/游标/事务
将会用到的几个表 mysql> DESC products; +------------+--------------+------+-----+---------+-------------- ...
- MySQL存储过程和临时表
MySQL创建存储过程 MySQL中,创建存储过程的基本形式如下: CREATE PROCEDURE sp_name ([proc_parameter[,...]]) [characteristic ...
- php调用mysql存储过程游标
<?php $dbtype = 'mysql'; $host = 'localhost'; $dbname = 'test'; $dsn = "$dbtype:host=$host;d ...
- MySQL 存储过程游标
一.创建游标 游标用declare语句创建.如下面的例子所示: create procedure test2() begin declare cursorTest cursor for select ...
随机推荐
- Spring中Bean生命周期
Spring中的bean生命周期是一个重要的点,只有理解Bean的生命周期,在开发中会对你理解代码是非常有用的.对于Bean的周期,个人认为可以分为四个阶段.第一阶段:Bean的实例化,在该阶段主要是 ...
- GDPR或使全球域名whois信息被隐藏
什么是GDPR? GDPR 全称为 General Data Protection Regulation,是欧盟 2016 年 4 月通过的一项通用数据保护条例(或称“一般数据保护法案”),是 199 ...
- spring boot 知识点1
spring boot: 1. 可以在pom文件中添加依赖sping-boot-properties-migrator来对项目进行升级,升级完成后,删除即可. 2. 关于日志的配置,参考:http:/ ...
- hdu 4602 Partition 矩阵快速幂
Partition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Proble ...
- Struts2框架学习第二章——Struts2下的HelloWorld
本章要点 — Struts 2的下载和安装 — 纯手工创建一个Web应用 — 纯手工创建一个Struts 2应用 — 实现Struts 2的Action — 配置Struts 2的Action — ...
- input实现文件上传
input实现文件上传 input + ajax 实现文件上传,包括文件大小及类型的判断 一.html <input type="file" id="file&qu ...
- LeetCode第[79]题(Java):Word Search(矩阵单词搜索)
题目:矩阵单词搜索 难度:Medium 题目内容: Given a 2D board and a word, find if the word exists in the grid. The word ...
- AtCoder Regular Contest 078D
两边bfs,先一边找到从1到n的路径并记录下来,然后挨个标记,最后一边bfs找1能到达的点,比较一下就行了 #include<map> #include<set> #inclu ...
- hadoop1.2.1伪分布模式安装教程
1:软件环境准备 1.1Hadoop: 我们使用hadoop Release 1.2.1(stable)版本,下载链接: http://mirrors.ustc.edu.cn/apache/hadoo ...
- js排序算法02——插入排序
插入排序的思路是我们默认数组的第一个元素是有序的,从第二个元素开始依次和前面的元素比较,如果前面的元素大,就将前面的元素往后移一位,如果前面的元素小,就把该元素放在前面元素的后面.其实就和我们玩扑克牌 ...