执行Mysql存储过程脚本报错【ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manua】
命令行执行mysql存储过程脚本时,报错:ERROR 1064 (42000) at line 1: 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 '' at line 4
查找原因,mysql语句默认分隔符“;”,在执行存储过程脚本时,认为还没结束,实际上的存储过程脚本还没结束。
解决:存储过程脚本前后加DELIMITER改变命令行的语句分隔符
delimiter //
//
delimiter //
CREATE PROCEDURE `my_procedure`()
BEGIN
if 1=1 then
select '相等';
else
select '不相等';
end if;
END
//
call my_procedure();
DROP PROCEDURE IF EXISTS `my_procedure`;