我试图在我的SQL上学习触发器并获得以下错误

时间:2016-12-23 07:51:48

标签: mysql triggers

这是我正在执行的代码

create trigger salarydifff  
after update on office  
for each row  
declare sal_diff number  
begin  
sal_diff := :new.salary- :old.salary  
end

我收到以下错误:

Error Code : 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 'declare sal_diff number begin sal_diff := :new.salary- :old.salary end' at line 4

1 个答案:

答案 0 :(得分:0)

您的代码看起来像Oracle而不是mysql Mysql看起来像这样

drop trigger if exists salarydiff;
delimiter //

create trigger salarydifff  
after update on office 
for each row  
begin
declare sal_diff integer ; 

set sal_diff = new.amt - old.amt ; 
end //

delimiter ;