一般来说,我对 SQL 相当陌生,对 MySQL 更是如此,我遇到了一个绊脚石。如果原始字段不为空,我正在尝试使用一个过程将一个字段的值复制到另一个字段,然后每当表更新或插入新行时,触发器都会调用此过程。这是我到目前为止所拥有的:
-- WORK_NOTES_PROCEDURE - This copies the contents of the estimate notes to the work order notes if the original estimate had any notes with it.
DROP PROCEDURE IF EXISTS 'WORK_NOTES_PROCEDURE';
DELIMITER $$
CREATE PROCEDURE WORK_NOTES_PROCEDURE()
BEGIN
DECLARE var_temp VARCHAR(50);
SET var_temp := (SELECT ESTIMATE_NOTES FROM ESTIMATES WHERE ESTIMATES.ESTIMATE_NUMBER = WORK_ORDERS.ESTIMATE_NUMBER);
IF var_temp IS NOT NULL THEN
UPDATE WORK_ORDERS SET WORK_ORDER_NOTES = var_temp WHERE WORK_ORDERS.ESTIMATE NUMBER = ESTIMATES.ESTIMATE_NUMBER;
END IF;
END$$
DELIMITER ;
绝对任何帮助将不胜感激,我得到的错误是我为 var_temp 赋值的行的语法错误。