2016-10-22 47 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