create triggers - error at DECLARE

∥☆過路亽.° 提交于 2019-12-03 18:15:22

问题


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

and error:

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

why? i use MySQL 5.5.8 and phpmyadmin 3.3.9


回答1:


did you specify delimiters ?

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 ;


来源:https://stackoverflow.com/questions/6292158/create-triggers-error-at-declare

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!