问题
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