如何使用存储过程设置新的触发器值?例如,在插入 myTable 之前,我想将 myTable.someColumn 的新值设置为给定值。尝试这样做时,我在尝试创建过程时收到 1193 错误。谢谢
DELIMITER $$
CREATE PROCEDURE `myProc` ()
BEGIN
//How do I set NEW.someColumn of myTable?
SET NEW.someColumn=123;
END$$
CREATE TRIGGER myTrig BEFORE INSERT ON myTable FOR EACH ROW
BEGIN
//SET NEW.someColumn=123; //This works, but I want to do the setting within the stored procedure
CALL myProc();
END$$
DELIMITER ;
INSERT INTO myTable(id,data) VALUES (1,"hello");
//Above "should" really do INSERT INTO myTable(id,data,someColumn) VALUES (1,"hello",123);
1193 - 未知系统变量“someColumn”
编辑。以下将起作用。
DELIMITER $$
CREATE PROCEDURE `myProc` (INOUT myID int)
BEGIN
SET myID =123;
END$$
CREATE TRIGGER myTrig BEFORE INSERT ON myTable FOR EACH ROW
BEGIN
CALL myProc(NEW.someColumn);
END$$
DELIMITER ;