Mysql CASE NOT FOUND 用于存储过程上的 CASE 语句
我正在尝试创建一个具有多个 CASE 语句的存储过程 我有以下存储过程:
BEGIN
CASE @olds
WHEN 'emp' THEN
CASE @news
WHEN 'loc' THEN
UPDATE equipos SET pe=pe-1,pg=pg+1 WHERE id=@eqloc;
UPDATE equipos SET pe=pe-1,pp=pp+1 WHERE id=@eqvis;
UPDATE partidos SET `eqgan`=@news WHERE id=@mst;
UPDATE log_partidos SET `status`=@news WHERE `match`=@mst;
WHEN 'vis' THEN
UPDATE equipos SET pe=pe-1,pg=pg+1 WHERE id=@eqvis;
UPDATE equipos SET pe=pe-1,pp=pp+1 WHERE id=@eqloc;
UPDATE partidos SET `eqgan`=@news WHERE id=@mst;
UPDATE log_partidos SET `status`=@news WHERE `match`=@mst;
END CASE;
WHEN 'loc' THEN
CASE @news
WHEN 'emp' THEN
UPDATE equipos SET pe=pe+1,pg=pg-1 WHERE id=@eqloc;
UPDATE equipos SET pe=pe+1,pp=pp-1 WHERE id=@eqvis;
UPDATE partidos SET `eqgan`=@news WHERE id=@mst;
UPDATE log_partidos SET `status`=@news WHERE `match`=@mst;
WHEN 'vis' THEN
UPDATE equipos SET pp=pp-1,pg=pg+1 WHERE id=@eqvis;
UPDATE equipos SET pg=pg-1,pp=pp+1 WHERE id=@eqloc;
UPDATE partidos SET `eqgan`=@news WHERE id=@mst;
UPDATE log_partidos SET `status`=@news WHERE `match`=@mst;
END CASE;
WHEN 'vis' THEN
CASE @news
WHEN 'emp' THEN
UPDATE equipos SET pe=pe+1,pg=pg-1 WHERE id=@eqvis;
UPDATE equipos SET pe=pe+1,pp=pp-1 WHERE id=@eqloc;
UPDATE partidos SET `eqgan`=@news WHERE id=@mst;
UPDATE log_partidos SET `status`=@news WHERE `match`=@mst;
WHEN 'loc' THEN
UPDATE equipos SET pp=pp-1,pg=pg+1 WHERE id=@eqloc;
UPDATE equipos SET pg=pg-1,pp=pp+1 WHERE id=@eqvis;
UPDATE partidos SET `eqgan`=@news WHERE id=@mst;
UPDATE log_partidos SET `status`=@news WHERE `match`=@mst;
END CASE;
END CASE;
END
每次执行此过程时,我都会收到以下错误:“未找到 CASE 语句的情况” 我做错了什么?
im trying to create a stored procedure that have multiples CASE STATEMENTS
I have the following stored procedure:
BEGIN
CASE @olds
WHEN 'emp' THEN
CASE @news
WHEN 'loc' THEN
UPDATE equipos SET pe=pe-1,pg=pg+1 WHERE id=@eqloc;
UPDATE equipos SET pe=pe-1,pp=pp+1 WHERE id=@eqvis;
UPDATE partidos SET `eqgan`=@news WHERE id=@mst;
UPDATE log_partidos SET `status`=@news WHERE `match`=@mst;
WHEN 'vis' THEN
UPDATE equipos SET pe=pe-1,pg=pg+1 WHERE id=@eqvis;
UPDATE equipos SET pe=pe-1,pp=pp+1 WHERE id=@eqloc;
UPDATE partidos SET `eqgan`=@news WHERE id=@mst;
UPDATE log_partidos SET `status`=@news WHERE `match`=@mst;
END CASE;
WHEN 'loc' THEN
CASE @news
WHEN 'emp' THEN
UPDATE equipos SET pe=pe+1,pg=pg-1 WHERE id=@eqloc;
UPDATE equipos SET pe=pe+1,pp=pp-1 WHERE id=@eqvis;
UPDATE partidos SET `eqgan`=@news WHERE id=@mst;
UPDATE log_partidos SET `status`=@news WHERE `match`=@mst;
WHEN 'vis' THEN
UPDATE equipos SET pp=pp-1,pg=pg+1 WHERE id=@eqvis;
UPDATE equipos SET pg=pg-1,pp=pp+1 WHERE id=@eqloc;
UPDATE partidos SET `eqgan`=@news WHERE id=@mst;
UPDATE log_partidos SET `status`=@news WHERE `match`=@mst;
END CASE;
WHEN 'vis' THEN
CASE @news
WHEN 'emp' THEN
UPDATE equipos SET pe=pe+1,pg=pg-1 WHERE id=@eqvis;
UPDATE equipos SET pe=pe+1,pp=pp-1 WHERE id=@eqloc;
UPDATE partidos SET `eqgan`=@news WHERE id=@mst;
UPDATE log_partidos SET `status`=@news WHERE `match`=@mst;
WHEN 'loc' THEN
UPDATE equipos SET pp=pp-1,pg=pg+1 WHERE id=@eqloc;
UPDATE equipos SET pg=pg-1,pp=pp+1 WHERE id=@eqvis;
UPDATE partidos SET `eqgan`=@news WHERE id=@mst;
UPDATE log_partidos SET `status`=@news WHERE `match`=@mst;
END CASE;
END CASE;
END
Everytime im executing this procedure i got the following error is: "Case not found for CASE statement"
What im doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是 MySQL 特有的问题。
在 MySQL 中,一个 case 必须始终有一个有效的匹配,因此有一个 ELSE 子句。
由于匹配后的语句不能为空,因此您可以用一个空块填充它,如下所示:
因此,有效的情况是,例如:
This is a MySQL specific problem.
In MySQL, a case must always have a valid match, thus an ELSE clause.
And as the statement after the match cannot be empty, you can fill it up with an empty block like so:
So a valid case would be, for example:
该错误意味着“case”语句之一找不到匹配项。您确定变量 olds 和 news 包含正确的值吗?尝试将每种情况下的最后一个“时间”更改为“其他”,然后看看您的程序是否有效。
That error means one of the 'case' statements can't find a match. Are you sure variables olds and news contain right values? Try to change last 'when' in each case to 'else' and see if your procedure works then.