带有if条件的mysql存储过程出现错误
下面是在mysql中创建存储过程的代码 但它给了我这个错误 错误1064 42000:您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以了解使用“else”附近的正确语法 选择“有超过4个stu”作为; 在第15行的“如果”结束 我做错了什么?提前感谢其工作原理如下带有if条件的mysql存储过程出现错误,mysql,if-statement,select,stored-procedures,Mysql,If Statement,Select,Stored Procedures,下面是在mysql中创建存储过程的代码 但它给了我这个错误 错误1064 42000:您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以了解使用“else”附近的正确语法 选择“有超过4个stu”作为; 在第15行的“如果”结束 我做错了什么?提前感谢其工作原理如下 CREATE DEFINER=`root`@`localhost` PROCEDURE `GetCustomerLevel`() BEGIN if(select count(name) from s
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
Mysql不允许在if else语句中使用begin/end。这仅适用于sql server
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