Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有if条件的mysql存储过程出现错误_Mysql_If Statement_Select_Stored Procedures - Fatal编程技术网

带有if条件的mysql存储过程出现错误

带有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

下面是在mysql中创建存储过程的代码

但它给了我这个错误

错误1064 42000:您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以了解使用“else”附近的正确语法 选择“有超过4个stu”作为; 在第15行的“如果”结束

我做错了什么?提前感谢

其工作原理如下

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