[英]MySQL - stored procedure not returning resultset
I created a procedure on MySQL 5.5.22-Ubuntu, and on my test it should return four rows but it is not returning anything. 我在MySQL 5.5.22-Ubuntu上创建了一个过程,并在我的测试中应返回四行,但未返回任何内容。 I already read it would be difficult to return a resultset and I tried a few approaches but none worked (as select... into @result...). 我已经读过,很难返回一个结果集,我尝试了几种方法,但是都没有用(将select转换为@result ...)。 Also, I tried to run the select out of the procedure, and it is returning, but when I run through the procedure, it just doesn't return anything. 另外,我尝试从过程中运行选择,并且它正在返回,但是当我运行过程时,它什么都没有返回。 Could anyone please assist me? 谁能帮我吗?
See below my procedure code: 见下面我的程序代码:
DELIMITER $$
DROP PROCEDURE IF EXISTS `switchboard3b-scheduler`.`getCurrentAndNextScheduleItem`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `getCurrentAndNextScheduleItem`(IN screenId int, IN scheduleId int
-- , OUT cursorScheduleItems int
)
BEGIN
-- select current item
-- declare cursorScheduleItems cursor for
(SELECT "CURRENT_ITEM" as "ITEM", si.id,si.start_time,si.end_time, si.play_through, c.filename,ct.command
FROM schedule_item si JOIN channel_content cc ON si.channel_content_id = cc.id
JOIN content c ON cc.content_id = c.id
JOIN content_type ct ON c.content_type_id = ct.id
WHERE si.channel_screen_id = @screenId
AND si.schedule_id = @scheduleId
AND (si.day=0 OR si.day=DAYOFWEEK(DATE(NOW())))
AND si.start_time <= NOW()
AND si.end_time > NOW()
ORDER BY si.day DESC, si.start_time DESC LIMIT 1)
-- select next item for that day
UNION ALL
(SELECT "NEXT_ITEM_TODAY" as "ITEM", si.id,si.start_time,si.end_time, si.play_through, c.filename,ct.command
FROM schedule_item si JOIN channel_content cc ON si.channel_content_id = cc.id
JOIN content c ON cc.content_id = c.id
JOIN content_type ct ON c.content_type_id = ct.id
WHERE si.channel_screen_id = @screenId
AND si.schedule_id = @scheduleId
AND (si.day=0 OR si.day=DAYOFWEEK(DATE(NOW())))
AND si.start_time > NOW()
ORDER BY si.day DESC, si.start_time ASC LIMIT 1)
-- select first two items of the next day
UNION ALL
(SELECT "NEXT_ITEMS_TOMORROW" as "ITEM", si.id,si.start_time,si.end_time, si.play_through, c.filename,ct.command
FROM schedule_item si JOIN channel_content cc ON si.channel_content_id = cc.id
JOIN content c ON cc.content_id = c.id
JOIN content_type ct ON c.content_type_id = ct.id
WHERE si.channel_screen_id = @screenId
AND si.schedule_id = @scheduleId
AND (si.day=0 OR si.day=DAYOFWEEK(DATE(NOW()+1)))
ORDER BY si.day DESC,si.start_time ASC LIMIT 2);
-- CLOSE cursorScheduleItems;
END $$
DELIMITER ;
I tried to call it with the command: 我试图用命令调用它:
CALL getCurrentAndNextScheduleItem(1,4);
Any tip would be appreciated. 任何提示将不胜感激。
Thanks in advance! 提前致谢!
What are you trying to return? 您想返回什么? its type is not mentioned in the create procedure. 创建过程中未提及其类型。
可能是您的“输出”参数带有注释-
-- , OUT cursorScheduleItems int
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.