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 ...
随机推荐
- SEM关键词的三种分类方式
关键词分类是为了使sem账户搭建结构清晰便于管理关键词.基于对需求人群的深入分析,每个账户都有其独特的分类方式,比如招商加盟行业更多的是地域分类,品牌类企业通常用词性分类即可,而冷门行业用人群分类比较 ...
- Permission denied: mod_fcgid
[Tue Jun 16 13:29:08 2015] [warn] (13)Permission denied: mod_fcgid: spawn process /var/www/cgi-bin/g ...
- 【Semantic segmentation】Fully Convolutional Networks for Semantic Segmentation 论文解析
目录 0. 论文链接 1. 概述 2. Adapting classifiers for dense prediction 3. upsampling 3.1 Shift-and-stitch 3.2 ...
- STL的其他用法(adjacent_find, find_first_of, sort_heap, merge, binary_search)总结
2017-08-20 17:26:07 writer:pprp 1.adjacent_find() 下面是源码实现: template <class ForwardIterator> Fo ...
- Spring Cloud 坑点
1 配置中心 1.config 默认Git加载 通过spring.cloud.config.server.git.uri指定配置信息存储的git地址,比如:https://github.com/spr ...
- 使用Github上传本地代码
最近在学习Python,但是每次写完代码后不知道该怎么跟家里的电脑进行同步.于是开始了学习github ,方法很简单 1:注册个git账号:https://github.com 2:本地安装git软件 ...
- Eclipse 使用中遇到的一些问题!
解决办法~ 1.先检查本地svn 版本与Eclipse 中svn插件 的区别 2.发现版本一致,没解决,发现如图 发现 svn接口报错 javaHL(JNI) Not Available!@ 所以 ...
- MySQL安装的N种方式
一.二进制包安装 1.)下载:在官网的下载页面下的服务器操作系统选择 Linux- Generic : 进制分发版的格式是:mysql-<版本>-<OS>-tar.gz 2. ...
- 前端构建大法 Gulp 系列
参考: 前端构建大法 Gulp 系列 (一):为什么需要前端构建 前端构建大法 Gulp 系列 (二):为什么选择gulp 前端构建大法 Gulp 系列 (三):gulp的4个API 让你成为gulp ...
- Linux查看和剔除当前登录用户
Linux查看和剔除当前登录用户 如何在linux下查看当前登录的用户,并且踢掉你认为应该踢掉的用户? 看了网络中的一些例子.在这里总结一下.主要用到的命令有,w,who,ps,kill,pkill ...