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 ; //
答案 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';