mysql – 创建触发器 – DECLARE出错

我从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 – You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server
version for the right syntax to use
near ” at line 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 ;
上一篇:mysql jdbc驱动程序不支持具有多个语句的触发器中的分隔符


下一篇:有没有办法检查MySQL触发器中的查询是否返回空集?