错误1064 mysql(42000)在`if then时省略分号;别的如果`结束

时间:2013-12-17 06:45:13

标签: mysql mysql-error-1064

ERROR 1064 (42000): 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 'if ;
end' at line 18
CREATE PROCEDURE UnitIdCheckForDelete( 
p_unitId varchar(50))
begin
if(
   (
    (
     SELECT ifnull(count(tbl_Product.unitId),0) 
     FROM  tbl_Product 
     WHERE   unitId=p_unitId
    ) > 0
   ) OR 
   (
    (
     SELECT ifnull(count(tbl_UnitConversion.unitId),0) 
     FROM tbl_UnitConversion 
     WHERE  tbl_UnitConversion.unitId=p_unitId
    ) > 0 
   )  
  )
then
SELECT 'true' ;
else
SELECT 'false'
end if ;
end ; //

2 个答案:

答案 0 :(得分:4)

试试这个:

DELIMITER //
CREATE PROCEDURE UnitIdCheckForDelete( 
p_unitId varchar(50))
begin
if(
   ((SELECT ifnull(count(tbl_Product.unitId),0) 
     FROM  tbl_Product 
     WHERE   unitId=p_unitId)>0) OR 
    ((SELECT ifnull(count(tbl_UnitConversion.unitId),0) 
      FROM tbl_UnitConversion 
      WHERE  tbl_UnitConversion.unitId=p_unitId)> 0 )  
    )
then SELECT 'true' ;
else SELECT 'false' ;
end if ;
end ; //

答案 1 :(得分:3)

您在以下语句的末尾缺少semicolun

SELECT 'false'

这句话应该像:(正如@nrathaus在评论中提到的那样)

SELECT 'false';