我在mysql触发器中声明了一些变量
DELIMITER //
CREATE TRIGGER lestrigger
AFTER INSERT ON examinations
FOR EACH ROW
BEGIN
DECLARE the_last_inserted_id INT ;
DECLARE the_class_id INT;
DECLARE the_year_id INT;
SET the_last_inserted_id = LAST_INSERT_ID();
SET the_class_id = select examination_class_id from examinations where examination_id = the_last_inserted_id;
SET the_year_id = select examination_class_year_id from examinations where examination_id = the_last_inserted_id;
insert into examination_data (ed_cs_id,ed_examination_id) select cs_id from class_students where cs_class_id = the_class_id AND cs_year_id = the_year_id,the_last_inserted_id;
END
//
DELIMITER ;
但我一直收到此错误
/ * SQL错误(1064):您的SQL语法有错误;检查 手册,对应右边的MySQL服务器版本 在考试中选择'select examination_class_id'附近使用的语法 其中exam_id = the_last_in'在第10行* /
我在语法上使用我的变量的方式是正确的吗?
答案 0 :(得分:0)
使用INTO
关键字http://dev.mysql.com/doc/refman/5.0/en/select-into.html
select examination_class_id into the_class_id from examinations where examination_id = the_last_inserted_id;
select examination_class_year_id into the_year_id from examinations where examination_id = the_last_inserted_id;