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 ...
随机推荐
- git-修改远程的URL
git remote set-url命令修改remote URL git remote set-url传递两个参数 remote name.例如,origin或者upstream new remote ...
- 混合开发的大趋势之一React Native与Android联调
转载请注明出处:王亟亟的大牛之路 先安利,有空我都会更,看到的好东西都会放进来:https://github.com/ddwhan0123/Useful-Open-Source-Android 公司某 ...
- jar包中使用log4j2不起作用
某程序中有使用到log4j2,将该程序打包成jar,使用以下命令执行时,发现log4j不输出 java -cp Tool.jar com.zhen.nameOnce.Log4jTest 且报以下错误 ...
- C# 随机数生成避免重复
public string GetMsgID() { Random rand = new Random((int)DateTime.Now.Ticks); string szRand = rand.N ...
- [OpenCV]OpenCV常用语法函数与坑点
目录 1. 加载图像(cv::imread) 2. 显示图像(cv::nameWindows与cv::imshow) 3. 修改图像(cv::cvtColor) 4. 保存图像(cv::imwrite ...
- Python学习札记(二十) 函数式编程1 介绍 高阶函数介绍
参考: 函数式编程 高阶函数 Note A.函数式编程(Functional Programming)介绍 1.函数是Python内建支持的一种封装,我们通过一层一层的函数调用把复杂任务分解成简单的任 ...
- rest 学习总结(最近不间断更新)
一.rest 简单介绍 1.http://www.zhihu.com/question/27785028 2.http://www.cnblogs.com/549294286/p/3524064.ht ...
- openstack dpdk
# ovs-vsctl showeef7cd95-0677-486c-b119-5d6ac8531c56 Manager "ptcp:6640:127.0.0.1" is_conn ...
- Shell 命令挂后台执行
使用nohup命令,结合& #!/bin/bash #挂后台执行文件 kimbo_test.sh nohup >& & 说明:0 是标准输入(STDIN),1 是标准输出 ...
- HDU1595-最短路-删边
find the longest of the shortest Time Limit: 1000/5000 MS (Java/Others) Memory Limit: 32768/32768 ...