mysql - 卡在存储过程上

标签 mysql stored-procedures

我有一个查询在最新的 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 ,不是存储过程级变量,因此 @idid 不同。此外,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/

相关文章:

sql-server - 返回 bool 的存储过程

sql - 如何在 RAISERROR 方法中打印 DateTime 变量?

php - Cakephp - 相关表

php - 全新安装 Laravel 5.2 Make :Auth onRegister does nothing

mysql - 具有大量连接的 laravel 查询构建

MySQL查询优化: UNION with rand()

mysql - 使用准备好的语句将表名保存在存储过程内的变量中

sql - 数据库字段中的逗号分隔值

mysql - 在2个表mysql中查找不同的记录

postgresql - Postgres 提交是否可以存在于具有异常 block 的过程中?