2016-10-22 91 views
0

我有以下代码在mysql中创建存储过程。mysql存储过程与if条件给出错误

mysql>delimiter | 
mysql>create procedure GetCustomerLevel() 
    -> if(select count(name) from s_marks)<4 
    -> then 
    -> begin 
    -> select 'inside the if statement' as''; 
    -> select 'there are lassee than 4 students' as ''; 
    -> end 
    -> else 
    ->  select 'there are more than 4 stu' as ''; 
    -> end if| 

但它给我这个错误

ERROR 1064(42000):你在你的SQL语法错误;检查与您的MySQL服务器版本相对应的手册,在'else '选择'有4个以上stu'作为''时使用正确的语法。 end if'at line 15

我在做什么错?在此先感谢

+1

MySQL不允许在其他如果只statement.That SQL Server的工作开始/结束 –

回答

0

了如下工作

CREATE DEFINER=`root`@`localhost` PROCEDURE `GetCustomerLevel`() 
BEGIN 
     if(select count(name) from s_marks)<4 
     then 

     select 'inside the if statement' as''; 
     select 'there are lassee than 4 students' as ''; 

     else 
     select 'there are more than 4 stu' as ''; 
     end if; 
END