BEGIN
DECLARE user_name VARCHAR(20);
DECLARE user_age INT;
IF (NEW.name='张三' && OLD.userAge>18) THEN
SELECT name, age INTO user_name, user_age FROM extra_info WHERE user_id = NEW.id;
INSERT into user_form (id,name,age,sex) values (null,user_name,user_age,new.sex)
else
...
END IF;
也可以使用 'set'
BEGIN
DECLARE user_name VARCHAR(20);
DECLARE user_age INT;
SET user_name = new.name;
IF (NEW.name='张三' && OLD.age>18) THEN
INSERT into user_form (id,name,age,sex) values (null,user_name,user_age,new.sex)
else
...
END IF;