mysql中触发器和存储过程的if-else中的子句不能为空

以下这样写会报错:

[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;

 

你可能感兴趣的:(数据库)