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 ...
随机推荐
- Tachyon:Spark生态系统中的分布式内存文件系统
转自: http://www.csdn.net/article/2015-06-25/2825056 摘要:Tachyon把内存存储的功能从Spark中分离出来, 使Spark可以更专注计算的本身, ...
- HTTP协议中的COOKIE机制简单理解
1.为什么会有COOKIE这种机制 首先一种场景, 在一个网站上面, 我发起一次请求,那服务器怎么知道我是谁?是谁发起的这次请求呢, HTTP协议是无状态的协议, 浏览器的每一次请求,服务器都当做一次 ...
- Chrome好用的插件:WhatRuns 查看网站使用的技术
Chrome好用的插件:WhatRuns 查看网站使用的技术 这是一款免费的Chrome扩展程序,使用很简单. chrome安装这个插件之后,打开要检测的网站,然后点击WhatRuns 的图标,就开始 ...
- ubuntu16.04 python3.5 opencv的安装与卸载(转载)
转载https://blog.csdn.net/qq_37541097/article/details/79045595 Ubuntu16.04 自带python2.7和python3.5两个版本,默 ...
- 【转】Python 字符串大小写转换
转载自:python 中字符串大小写转换 一.pyhton字符串的大小写转换, 常用的有以下几种方法: 1.对字符串中所有字符(仅对字母有效)的大小写转换,有两个方法: print 'just to ...
- 测试php语句执行时间
$start = microtime(true); $elapsed = microtime(true) - $start; echo "That took $elapsed seconds ...
- 关于java 线程池 ThreadPoolExceutor 之 TestDemo
public class App { public static void main(String[] args) throws InterruptedException { System.out.p ...
- 返回值过长时被nginx截断的解决办法
今天在写接口时碰到了这个问题,返回json格式的数据,但是被截断了经过排查,才发现是数据过大超出缓冲区最大容量,而将数据写入临时文件时又没有权限,所以再返回时,超出缓冲区的数据将丢失解决方法:给fas ...
- static、final和finalize详解
一.static 修饰符 数据共享 成员变量(实例变量)和静态变量(类变量)的区别 两个变量的生命周期不同 成员变量随对象的创建而存在,随对象被回收而释放 静态变量随类的加载而存在,随类的消失而消失 ...
- FlashFXP客户端 FTP连接,连接很慢的情况,
菜单栏-->站点-->站点管理器--->左边视图FTP--->列表命令选择 STAT -L