我有一个查询在最新的 mysql 中运行得很好。
select Title, Link
from PlaylistItem
where PlaylistId = 1;
返回:
+---------------------------+---------------------------------------------+
| Title | Link |
+---------------------------+---------------------------------------------+
| Regina Spektor - Fidelity | https://www.youtube.com/watch?v=wigqKfLWjvM |
+---------------------------+---------------------------------------------+
但是当我编写存储过程时,我得到一个空结果集。
存储过程如下所示:
/* Fetch all playlist items for a playlist */
delimiter //
create procedure MixtapeDating.GetPlaylist
(
in Id int
)
begin
select Id, Title, Link
from PlaylistItem
where PlaylistId = @Id;
end //
delimiter ;
我像这样运行程序:
call GetPlaylist(1);
最佳答案
在 mysql 中,以 @
为前缀的变量是 session variables ,不是存储过程级变量,因此 @id
与 id
不同。此外,id
也是一个字段名,因此您必须重命名您的参数。
delimiter //
create procedure MixtapeDating.GetPlaylist
(
in var_Id int
)
begin
select Id, Title, Link
from PlaylistItem
where PlaylistId = var_Id;
end //
delimiter ;
关于mysql - 卡在存储过程上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45183228/