mysql - 这个存储过程代码有什么问题?

标签 mysql

下面的代码给出了许多与分号相关的错误。我是 MySql 的新手,所以一无所知。

CREATE PROCEDURE `sp_get_orderbystatus`(p_status_id int)

BEGIN
declare v int;
if(p_status_id = 1) then
begin
    set v = 1;
end;
end if;

END

最佳答案

如果您尝试在 mysql cli 中执行此操作,则似乎需要更改 DELIMITER

DELIMITER // -- change the delimiter to '//' 

CREATE PROCEDURE `sp_get_orderbystatus`(p_status_id int)
    DECLARE v INT;
    -- the rest of the code of your procedure
END//

DELIMITER ; -- change it back to ';'

Defining Stored Programs
If you use the mysql client program to define a stored program containing semicolon characters, a problem arises. By default, mysql itself recognizes the semicolon as a statement delimiter, so you must redefine the delimiter temporarily to cause mysql to pass the entire stored program definition to the server.

关于mysql - 这个存储过程代码有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44864745/

相关文章:

mysql - 如何使用原始 Laravel 在 json_contains 中设置变量?

mysql - 插入 VARCHAR 列时自动修剪 CHAR 数据

mysql - 在 CakePHP 中从一个表中检索所有数据,并从另一个表中检索一些数据

php - MySql 获取列中每个 id 的列表,其中搜索 id 是一个数组

MySQL - 索引 innodb 外键

mysql - 按主键顺序插入行更快吗?

mysql - 用于在 docker MySQL 中创建默认用户的 Bash 脚本

c# - MySQL Entity Framework 在尝试添加时抛出异常

mysql - 具有较大自动增量值的行是否可以比具有较小自动增量值的行出现得更快?

php - 如何使用 Group by 语句从表中选择最新记录