我从http://forge.mysql.com/wiki/Triggers学习触发器, 并且有:
create trigger bi_emps_fer before insert on emps for each row begin declare newsal numeric default 0; declare namelength, l_loop int default 0; set namelength = length(new.emp_name); while l_loop < namelength do set newsal := newsal new.salary; set l_loop := l_loop 1; end while; set new.salary = newsal; end
和错误:
1064-您的SQL语法有误;检查与您的MySQL服务器版本相对应的手册以获取在第4行的’‘附近使用的正确语法
为什么?我使用MySQL 5.5.8和phpmyadmin 3.3.9
您是否指定了定界符?
delimiter # create trigger bi_emps_fer before insert on emps for each row begin declare newsal decimal(10,2) default 0; // do sql stuff here but not what you're doing ! set new.salary = newsal; end# delimiter ;