0

Having a question about drop events from MySQL

I see here already related a question which I see from far.

But I just want to know, How to drop events dynamically?

I have tried below way using procedure and it's not working as already posted question explained. So please suggest any other way if possible using MySQL instead of any PHP/Perl/Lua etc... scripts.

DELIMITER $$
CREATE PROCEDURE `delete_alerts` ()
BEGIN
    DECLARE test_event_id int;
    DECLARE test_event_name varchar(15);
    DECLARE drop_test_event_done TINYINT(1) DEFAULT 0;
    DECLARE drop_test_event_cursor CURSOR FOR SELECT `id` FROM `customize_events` where `event_type` IN (1,2,3);
        DECLARE CONTINUE HANDLER FOR NOT FOUND SET drop_test_event_done = TRUE;
        OPEN drop_test_event_cursor;
            read_loop: 
                LOOP
                    FETCH drop_test_event_cursor into test_event_id;
                    IF drop_test_event_done THEN
                        LEAVE read_loop;
                    END IF;
                    SET test_event_name = concat('custom_alert_',test_event_id);
                    DROP EVENT IF EXISTS test_event_name;
                END LOOP;
        CLOSE drop_test_event_cursor;
END
$$
DELIMITER ;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.