以下这样写会报错:
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'end if' at line 8
- create procedure test(in a int)
- if a > 1 then
- select 1;
- elseif a>2 then
- select 2;
- else
- end if;
应改成以下这样:
- create procedure test(in a int)
- if a > 1 then
- select 1;
- elseif a>2 then
- select 2;
- else
- -- do nothing --
- set @tmp=1;
- end if;
本文介绍了一个常见的MySQL存储过程语法错误,并给出了正确的写法。错误发生在使用ENDIF而非ENDIF结束条件语句时。正确的做法是在ELSE之后继续指定操作,或者用一个简单的SET语句作为占位符。
1万+

被折叠的 条评论
为什么被折叠?



