我有SQL Server的经验。这是我第一次使用mysql。我想在存储过程中创建一个临时表。我不知道我在这里错过了什么。

我想做的是:

循环遍历事件及其匹配项,并将这些匹配项插入到临时表中,然后从该临时表返回结果。

这是我的存储过程代码。

CREATE DEFINER=`root`@`localhost` PROCEDURE `APP_GetMatchListbyScoreboardOperatorID`(SOID int)

BEGIN

DECLARE eventid INT DEFAULT NULL;

DECLARE done1, done2 BOOLEAN DEFAULT FALSE;

DECLARE eventname varchar(500);

DECLARE eventdate varchar(100);

DECLARE numberOfMats int;

DECLARE backgroundLogo varchar(1500);

DECLARE categoryid int;

DECLARE categoryname varchar(500);

DECLARE sheettitle varchar(2000);

DECLARE matchid int;

DECLARE bracketmatchid int;

DECLARE parentid int;

DECLARE competitor1 long;

DECLARE competitor2 long;

DECLARE round int;

DECLARE matcheStatusDisplay varchar(500);

DECLARE sheetid long;

DECLARE matnumber int;

DECLARE starttime float;

DECLARE duration_category long;

DECLARE categorytimelimit int;

DECLARE numberoffights_category int;

CREATE TEMPORARY TABLE TempTable (eventid int) ;

#DECLARE done TINYINT DEFAULT FALSE;

-- declare a cursor to select the desired columns from the desired source table1

-- the input argument (which you might or might not need) is used in this example for row selection

DECLARE cursor_events -- cursor1 is an arbitrary label, an identifier for the cursor

CURSOR FOR SELECT EventId FROM scoreboardoperatoreventmapping WHERE ScoreboardOperatorID =SOID;

-- this fancy spacing is of course not required; all of this could go on the same line.

-- a cursor that runs out of data throws an exception; we need to catch this.

-- when the NOT FOUND condition fires, "done" -- which defaults to FALSE -- will be set to true,

-- and since this is a CONTINUE handler, execution continues with the next statement.

DECLARE CONTINUE HANDLER FOR NOT FOUND SET done1 = TRUE;

-- open the cursor

OPEN cursor_events;

my_loop: -- loops have to have an arbitrary label; it's used to leave the loop

LOOP

-- read the values from the next row that is available in the cursor

FETCH cursor_events INTO eventid;

IF done1 THEN -- this will be true when we are out of rows to read, so we go to the statement after END LOOP.

LEAVE my_loop;

ELSE -- val1 and val2 will be the next values from c1 and c2 in table t1,

-- so now we call the procedure with them for this "row"

BLOCK1 : BEGIN

DECLARE cur2 CURSOR FOR

Select e.eventname,e.eventdate,e.numberOfMats,e.backgroundLogo, s.categoryid,s.categoryname,s.sheettitle,m.matchid,m.bracketmatchid,m.parentid,m.competitor1,m.competitor2,m.round,ms.MatchStatus as matcheStatusDisplay,

s.sheetid,s.matnumber,s.starttime,s.duration_category,s.categorytimelimit,s.numberoffights_category

from events e

LEFT JOIN matches m on e.eventid= m.eventid AND m.eventid=eventId

LEFT JOIN matchstatus ms on m.matcheStatus=ms.Id AND m.matcheStatus in (select id from matchstatus where (matcheStatus!='Completed'))

LEFT JOIN sheets s on s.sheetid=m.sheetid AND s.eventid=eventId

where e.eventid=eventId and m.round!=-1 order by matnumber, starttime , categoryid, round, parentid;

DECLARE CONTINUE HANDLER FOR NOT FOUND SET done2 = TRUE;

open cur2;

loop2 : LOOP

FETCH cur2 INTO eventname,eventdate,numberOfMats,backgroundLogo, categoryid,categoryname,sheettitle,

matchid,bracketmatchid,parentid,competitor1,competitor2,round,matcheStatusDisplay,

sheetid,matnumber,starttime,duration_category,categorytimelimit,numberoffights_category;

if done2 THEN

CLOSE cur2;

SET done2 = FALSE;

LEAVE loop2;

end if;

select eventId,matchid,eventname,4;

END LOOP loop2;

END BLOCK1;

-- maybe do more stuff here

END IF;

END LOOP;

select 4;

END

创建临时表时出现错误,要求在分号后添加“end”。但这就结束了这一过程。我没有得到什么是正确的语法来实现这一点。我也做过同样的研发。但从所有的参考资料来看,我得到的是同样的语法在起作用。你能告诉我这里少了什么吗?

mysql 过程 临时表_在存储过程mysql中创建临时表相关推荐

  1. mysql 生成日历表_如何在SQL中创建100年的日历表

    下面是可以在SQL Server中使用的通用脚本.只需修改开始日期和结束日期: IF EXISTS (SELECT * FROM information_schema.tables WHERE Tab ...

  2. mysql语句创建临时表并存入数据_mysql实例:在存储过程中创建临时表并储存数据...

    在mysql存储过程中创建临时表,并保存数据到该表,然后根据存储过程调用的例子. 是学习mysql存储过程的好例子,值得参考. 代码: mysql> mysql> CREATE TABLE ...

  3. mysql 避免使用临时表_从日期范围中选择时防止MySQL使用临时表

    我试图阻止mysql在此查询中创建临时表 SELECT `vendor_id`,SUM(`qty`) AS `qty` FROM `inventory_transactions` WHERE `inv ...

  4. java 创建临时表 oracle_在ORACLE存储过程中创建临时表

    在ORACLE存储过程中创建临时表 存储过程里不能直接使用DDL语句,所以只能使用动态SQL语句来执行 --ON COMMIT DELETE ROWS 说明临时表是事务指定,每次提交后ORACLE将截 ...

  5. oracle数据存入临时表,oracle中创建临时表步骤

    当前位置:我的异常网» 数据库 » oracle中创建临时表步骤 oracle中创建临时表步骤 www.myexceptions.net  网友分享于:2014-06-08  浏览:4次 oracle ...

  6. 在内存中创建临时表和表变量

    在Disk-Base数据库中,由于临时表和表变量的数据存储在tempdb中,如果系统频繁地创建和更新临时表和表变量,大量的IO操作集中在tempdb中,tempdb很可能成为系统性能的瓶颈.在SQL ...

  7. mysql 临时列_如何在MySQL中列出临时表列?

    要列出MySQL中的临时表列,让我们首先创建一个临时表. 这是一个例子.我们创建了一个临时表,其中包含一些列,其中包括学生的详细信息-mysql> CREATE TEMPORARY TABLE  ...

  8. mysql sql优化_浅谈mysql中sql优化

    说到sql优化,一般有几个步骤呢,在网上看到了一篇很不错的帖子.在这分享一下吧,也是自己学习的一个过程. 一.查找慢查询 1.1.查看SQL执行频率 SHOW STATUS LIKE 'Com_%'; ...

  9. mysql表空间_浅谈mysql中各种表空间(tablespaces)的概念

    mysql中,会涉及到各种表空间的概念,虽然,很多方面这些概念和Oracle有相似性,但也有很多不同的地方,初学者很容易被这些概念弄的晕头转向,从而,混淆这些概念的区别和理解,下面,就简要介绍和说明一 ...

最新文章

  1. Scratch青少年编程能力等级测试模拟题(一级)
  2. public lt;Tgt; void method,此地泛型的意思
  3. c语言if-else的效率比较
  4. 撩课-Web大前端每天5道面试题-Day38
  5. 微软CEO鲍尔默力推HTML5:称其为平台的粘合剂
  6. sudo apt-get install 安装软件总是出现“404 NOT FOUND” 错误的解决方案 !
  7. hadoop+spark生态系统操作与指南非影印版_Spark背景知识学习
  8. HTML5新增的标签
  9. 不常用≠没用 Win7容易忽略的四个功能
  10. activiti脚本任务_Activiti中的安全脚本如何工作
  11. 重启模块与及关开邮件存储设置功能页面-PHP-shell-py
  12. 定时器_Qt定时器小坑
  13. linux msgctl函数,msgctl()函数
  14. bat 取得服务列表_临汾进出口经营者备案,查看详情_共勤外贸服务
  15. 如何安装和配置Tomcat(全网最详)
  16. 机器人操作系统——ROS,Robot Operating System
  17. 《大数据之路:阿里巴巴大数据实践》-第1篇 数据技术篇 -第3章数据同步
  18. xp访问计算机组提示没有权限,WindowsXP系统提示没有权限使用网络怎么办
  19. 软件测试的环境部署怎么做?
  20. SAP 采购订单税率计算、单价取值(S4)

热门文章

  1. 我的世界服务器无限开号,我的世界1.7.X-1.12.X无限瞬间生存服务器
  2. Python读取Excel中的数据
  3. Vue学习疑问:你一口一个渲染、挂载所以到底应该怎么理解?
  4. 投资信托学习笔记(二)
  5. 世界上最管用的七句话(很灵哦)
  6. 查看word文档的修改痕迹
  7. Vue高级篇--实现前后端完全分离
  8. Fast CU Depth Decision Algorithm for HEVC Intra Coding
  9. 【一周头条盘点】中国软件网(2018.10.22~2018.10.26)
  10. 向eclipse中倒入存在的文件之后报错