创建触发器时出现MySQL语法错误

时间:2014-11-28 16:00:58

标签: mysql syntax triggers

创建以下触发器

DELIMITER $$

CREATE TRIGGER NUMERO_OS AFTER INSERT ON custom_values
FOR EACH ROW
BEGIN

IF NEW.custom_field_id = 4 AND NEW.customized_type = 'Issue' THEN

    SET @os = (SELECT MAX(SUBSTRING(value FROM 1 FOR 3)) + 1 FROM custom_values WHERE customized_type = 'Issue' AND custom_field_id = 4 AND SUBSTRING(value FROM 5 FOR 8) = YEAR(CURDATE()));

    IF @os = NULL THEN

        @os = '001';

    END IF;

END IF;

END$$
DELIMITER ;

我在@os ='001'附近出现“语法错误”;“。

我应该怎么做才能运行MySQL Trigger?

1 个答案:

答案 0 :(得分:0)

尝试重复set

IF @os IS NULL THEN
    SET @os = '001';
END IF;