我在mysql上创建一个触发器时遇到异常,在下面粘贴我的触发器。我希望这个触发器中的prepare语句抛出此异常,请在语法中纠正我的任何错误。
DELIMITER $$
CREATE DEFINER=`root`@`localhost` TRIGGER mysql_common.mysql_alert_trigger after insert on mysql_common.alert FOR EACH ROW
BEGIN
set @col_string = "col1,col2,col3";
set @val_string = "('val1','val2','val3')";
SET @s := CONCAT('INSERT into msql_common.seperated_processlist(',@col_string,') values ', @val_string);
PREPARE dynamic_statement FROM @s;
EXECUTE dynamic_statement;
DEALLOCATE PREPARE dynamic_statement;
END $$
DELIMITER ;
答案 0 :(得分:0)
DELIMITER $$
CREATE DEFINER=`root`@`localhost` TRIGGER mysql_common.mysql_alert_trigger after insert on mysql_common.alert FOR EACH ROWEACH ROW
BEGIN
call SOME_PROC();
END $$
DELIMITER ;
您可以使用业务逻辑编写一个过程,并使用您的特定输入和输出参数从触发器调用该过程,如上面的代码所示。
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `SOME_PROC`()
BEGIN
set @col_string = "col1,col2,col3";
set @val_string = "('val1','val2','val3')";
SET @s := CONCAT('INSERT into msql_common.seperated_processlist(',@col_string,') values ', @val_string);
PREPARE dynamic_statement FROM @s;
EXECUTE dynamic_statement;
DEALLOCATE PREPARE dynamic_statement;
END$$
DELIMITER ;
希望这会有所帮助。