CREATE EVENT EVENT_NOTIFICATION
ON SCHEDULE
EVERY 1 DAY STARTS '2013-10-15 15:42:00'
COMMENT 'Insert Notification'
DO CALL
sp_Notification();
SP_notificationStatus();
我想一个接一个地执行上面两个过程'sp_Notification'和'SP_notificationStatus',但只执行'sp_Notification'过程。
如何使用一个事件执行2个程序?
答案 0 :(得分:1)
我遇到了同样的问题,第二个程序被立即调用,这就是答案:
DELIMITER // -- THIS IS IMPORTANT!!!!
CREATE EVENT EVENT_NOTIFICATION
ON SCHEDULE
EVERY 1 DAY
STARTS '2013-10-15 15:42:00'
COMMENT 'Insert Notification'
DO
BEGIN
CALL sp_Notification(); -- Otherwise you event will end HERE after ;
CALL SP_notificationStatus();
END;
END // -- Set delimiter back to ';'
DELIMITER ;
答案 1 :(得分:0)
我想你想要这个:
CREATE EVENT EVENT_NOTIFICATION
ON SCHEDULE
EVERY 1 DAY STARTS '2013-10-15 15:42:00'
COMMENT 'Insert Notification'
DO CALL
sp_Notification();
CREATE EVENT EVENT_NOTIFICATION
ON SCHEDULE
EVERY 1 DAY STARTS '2013-10-15 15:42:00'
COMMENT 'Insert Notification'
DO CALL
SP_notificationStatus();
您也可以创建一个调用它们的新程序,然后安排一次。
答案 2 :(得分:0)
您错过了CALL
声明:
CREATE EVENT EVENT_NOTIFICATION
ON SCHEDULE
EVERY 1 DAY STARTS '2013-10-15 15:42:00'
COMMENT 'Insert Notification'
DO
BEGIN
CALL sp_Notification();
CALL SP_notificationStatus();
END;
答案 3 :(得分:0)
以下配置运行两个存储过程:
/*!50106 set global event_scheduler = 1*/;
/*Table structure for table `notification` */
DROP TABLE IF EXISTS `notification`;
CREATE TABLE `notification` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`mydate` DATETIME DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=INNODB;
/*Table structure for table `notificationStatus` */
DROP TABLE IF EXISTS `notificationStatus`;
CREATE TABLE `notificationStatus` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`mydate` DATETIME DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=INNODB;
/* Event structure for event `EVENT_NOTIFICATION` */
/*!50106 DROP EVENT IF EXISTS `EVENT_NOTIFICATION`*/;
DELIMITER $$
/*!50106 CREATE EVENT `EVENT_NOTIFICATION` ON SCHEDULE EVERY 5 SECOND
STARTS '2013-10-12 00:00:00' ON COMPLETION NOT PRESERVE ENABLE
DO
BEGIN
CALL `sp_Notification`();
CALL `sp_notificationStatus`();
END */$$
DELIMITER ;
/* Procedure structure for procedure `sp_Notification` */
/*!50003 DROP PROCEDURE IF EXISTS `sp_Notification` */;
DELIMITER $$
/*!50003 CREATE PROCEDURE `sp_Notification`()
BEGIN
INSERT INTO `notification` (`mydate`) VALUES (NOW());
END */$$
DELIMITER ;
/* Procedure structure for procedure `sp_notificationStatus` */
/*!50003 DROP PROCEDURE IF EXISTS `sp_notificationStatus` */;
DELIMITER $$
/*!50003 CREATE PROCEDURE `sp_notificationStatus`()
BEGIN
INSERT INTO `notificationStatus` (`mydate`) VALUES (NOW());
END */$$
DELIMITER ;
答案 4 :(得分:0)
DELIMITER //
创建活动EVENT_NOTIFICATION
安排时间表
每一天开始' 2013-10-15 15:42:00'
评论'插入通知' DO
BEGIN
CALL sp_Notification();
CALL SP_notificationStatus();
结束//
答案 5 :(得分:0)
我认为通过使用以下方法,您可以在一个事件中执行多个过程
DELIMITER $$
CREATE EVENT Raju_RemoveExpiredItemsEvent
ON SCHEDULE EVERY 1 DAY
DO
BEGIN
CALL Raju_DeleteExpiredItems('comments');
CALL Raju_DeleteExpiredItems('likes');
END$$
DELIMITER ;
答案 6 :(得分:0)
当我遇到类似问题时,以上答案对我不起作用。
我通过创建一个新的存储过程来解决它,该存储过程包括事件中所需的过程。
示例
CREATE PROCEDURE `new_procedure` ()
BEGIN
sp_Notification();
SP_notificationStatus();
END
,并且在事件中
CREATE EVENT EVENT_NOTIFICATION
ON SCHEDULE
EVERY 1 DAY STARTS '2013-10-15 15:42:00'
COMMENT 'Insert Notification'
DO
CALL new_procedure();