创建触发器 - DECLARE 时出错

2022-01-01 00:00:00 sql mysql phpmyadmin triggers declare

我从 http://forge.mysql.com/wiki/Triggers 学习触发器我有:

i learn triggers from http://forge.mysql.com/wiki/Triggers and i have:

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 行的 '' 附近

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

why? i use MySQL 5.5.8 and 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 ;

相关文章