1
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 个过程?

4

7 回答 7

1

你想要这个:

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();

您还可以创建一个调用它们的新过程,然后安排一次。

于 2013-10-15T10:25:34.627 回答
0

DELIMITER //
创建事件 EVENT_NOTIFICATION 按
计划
每 1 天开始 '2013-10-15 15:42:00'
COMMENT 'Insert Notification' DO
BEGIN
CALL sp_Notification();
调用 SP_notificationStatus();
结尾 //

于 2014-07-09T12:40:34.860 回答
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 ;
于 2013-10-15T12:52:07.967 回答
0

我遇到了同样的问题,第二个程序被立即调用,这是答案:

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 ;
于 2016-12-12T11:35:02.893 回答
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();
于 2020-09-17T12:02:45.347 回答
-1

你错过了一个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;
于 2013-10-15T10:29:13.470 回答
-1

我认为通过使用以下方法,您可以在一个事件中执行多个过程

DELIMITER $$

CREATE EVENT Raju_RemoveExpiredItemsEvent
ON SCHEDULE EVERY 1 DAY

DO
  BEGIN
        CALL Raju_DeleteExpiredItems('comments');
        CALL Raju_DeleteExpiredItems('likes');
        END$$

DELIMITER ;
于 2016-07-15T10:11:28.973 回答