有人知道我的触发器声明有什么问题吗?
CREATE TRIGGER `sch_trigger_curriculum_subject_before_insert` BEFORE INSERT ON
`sch_curriculum_subject` FOR EACH ROW
BEGIN
DECLARE curriculum_code VARCHAR(50);
SET curriculum_code = SELECT code FROM sch_curriculum WHERE id=NEW.id;
SET NEW.`code_name` = CONCAT(curriculum_code,' - ', NEW.code,' - (',NEW.name,')');
END;
错误:SQL 错误(1064):您的 SQL 语法有错误.....在第 4 行的 '' 附近。
根据错误消息,我的课程代码声明有问题。但我无法找出问题所在。
提前致谢
更新: 已经解决,问题出在分隔符上,这是工作的
DELIMITER $$
CREATE TRIGGER `sch_trigger_curriculum_subject_before_insert` BEFORE INSERT ON
`sch_curriculum_subject` FOR EACH ROW
BEGIN
DECLARE curriculum_code VARCHAR(50);
SET curriculum_code = (SELECT code FROM sch_curriculum WHERE id=NEW.id);
SET NEW.`code_name` = CONCAT(curriculum_code,' - ', NEW.code,' - (',NEW.name,')');
END$$