MySQL 存储过程,游标,临时表创建
2014-04-04 10:59
751 查看
-- -------------------------------------------------------------------------------- -- 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字符串截取函数SUBSTRING的用法说明
- MYSQL用户权限管理(Grant,Revoke)
- MySQL for Mac 安装和基本操作
- mysqldump无法备份 锁表的解决方案
- MySQL索引的查看创建和删除
- 并发链接,大批量写入数据的mysql插入优化
- Mysql优化与使用集锦
- mysql 创建数据库使用默认字符集(备忘)
- Mysql:is not allowed to connect to this MySQL server
- 解决/usr/bin/ld: cannot find -lmysqlclient错误
- check the manual that corresponds to your MySQL server version for the right syntax to use near
- mysqldump主要参数探究
- 使用EntityFramework6连接MySql数据库(db first方式)
- 【转载】mysql 性能优化方案
- 编译安装mysql
- 如何导入导出MySQL数据库
- MySQL引擎介绍
- MySql存储过程详解
- mysql忘记密码怎么办?
- powerdesigner mysql5 逆向工程(建立mysql数据源)