-- --------------------------------------------------------------------------------
-- 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 存储过程,游标,临时表创建的更多相关文章

  1. MySQL存储过程 游标

    MySQL存储过程  游标 如何在存储过程中使用MySQL游标来遍历SELECT语句返回的结果集 MySQL游标简介 要处理存储过程中的结果集,请使用游标.游标允许您迭代查询返回的一组行,并相应地处理 ...

  2. mysql存储过程游标嵌套循环

    自己写的一个mysql存储过程如下: BEGIN DECLARE _did bigint(20);DECLARE _count int;DECLARE s1 int;DECLARE cur_1 CUR ...

  3. mysql 存储过程、视图---创建、调用、删除

    之前一直用的是Sql Server数据库,最近偶然机会接触到mysql.这里总结了关于mysql 存储过程.视图的“创建.调用.删除”示例 ============================== ...

  4. mysql存储过程游标加计划任务事件调度器

    存储过程加事件调度器 -- 存储过程 (多个)游标的使用 临时表的使用(让执行时间从一个小时降低到5分钟)DELIMITER $$ DROP PROCEDURE IF EXISTS `eval_cal ...

  5. 菜鸟使用MySQL存储过程and临时表,供新手参考,请高手斧正

    因为公司最近的一个项目,第一次用到了MySQL(5.10版本),之前听传说MySQL很厉害的样子,因为开源而神奇,但是现在用起来, 感觉并不好啊!我知道是我水平太down,呜呜呜,请各路神仙略施小技, ...

  6. MySQL 存储过程/游标/事务

    将会用到的几个表 mysql> DESC products; +------------+--------------+------+-----+---------+-------------- ...

  7. MySQL存储过程和临时表

    MySQL创建存储过程 MySQL中,创建存储过程的基本形式如下: CREATE PROCEDURE sp_name ([proc_parameter[,...]]) [characteristic ...

  8. php调用mysql存储过程游标

    <?php $dbtype = 'mysql'; $host = 'localhost'; $dbname = 'test'; $dsn = "$dbtype:host=$host;d ...

  9. MySQL 存储过程游标

    一.创建游标 游标用declare语句创建.如下面的例子所示: create procedure test2() begin declare cursorTest cursor for select ...

随机推荐

  1. http://www.jb51.net/article/28619.htm

    http://www.jb51.net/article/28619.htm js autocomplete 自动完成

  2. Visual Studio 2010生成解决方案时,导致C盘空间越来越小

    为了从根本上解决问题,还是去掉智能跟踪选项吧,方案: VS2010-->工具-->选项-->IntelliTrance-->将“启用IntelliTrace”勾选去掉--> ...

  3. SaltStack匹配target-第六篇

    练习内容 Salt远程执行中目标选择常用的模式 1.通配符匹配 2.正则表达式匹配 3.List支持 4.Grains匹配 5.IP地址匹配 6.混合匹配 7.Node groups 远程执行格式 t ...

  4. PLMN和PSTN

    一.PLMNPLMN公众陆地移动电话网(PLMN) public land mobile network 由政府或它所批准的经营者,为公众提供陆地移动通信业务目的而建立和经营的网路.该网路必须与公众交 ...

  5. bzoj1879: [Sdoi2009]Bill的挑战(codevs2308)(luoguP2167) 状压dp

    唔...懒兔子来写博客了... 点我看题 这题的话...我想了很久但是都不是可行解 刚开始想预处理任意两个串是否可以匹配然后在乱搞,后来发现完全不会写... 然后按照惯例,我会看题解认真的思考... ...

  6. Mybatis动态SQL——if,where,trim,choose,set.foreach的用法

    知识点:主要介绍mybatis中,动态sql中的if,where,trim,set,foreach的用法 自学谷粒学院mybatis学习视频,参考mybatis官方文档 java包:log4j.jar ...

  7. L1-3 宇宙无敌加法器 - 令人激动的一道题目

    L1-3 宇宙无敌加法器 - 令人激动的一道题目 感觉好久没有这么认真的做一道题了,今天看到一句话, 说是编程是一个工程型的工作,想要学好,"无他,唯手熟尔" 之前觉得自己笨,怀疑 ...

  8. 综合一句话Shell破解

    之前我在论坛发过了一句话的破解工具. 所以决定还是在基础上在改改,符合某些人的利用. 上一版只支持HTTPS/ASPX,这次改进后,也算是最后一版. 支持:PHP/HTTP/HTTPSASPX/HTT ...

  9. SVM(三)线性支持向量机

    本文是在微信公众号发表的原创~ 额,图片粘不过来~就把链接给你们吧 http://mp.weixin.qq.com/s?__biz=MjM5MzM5NDAzMg==&mid=400740076 ...

  10. CALL_AND_RETRY_LAST Allocation failed node打包报错

    全局安装increase-memory-limit: npm install -g increase-memory-limit 进入工程目录,执行: increase-memory-limit