Mysql:触发器出错

时间:2016-03-03 14:55:37

标签: mysql triggers

这是我试图添加的触发器。但这是错误信息:

  

#1064 - 您的SQL语法出错;检查与MySQL服务器版本对应的手册,以获得正确的语法   在&nuss_order`上插入之前创建触发器tgr_insert   每一排'在第2行。

delimiter $$
drop trigger if exists tgr_insert
create trigger tgr_insert before insert on `nuss_order`  
for each row 
begin  
  declare a int;declare b varchar(14);declare d varchar(8);  
  set a = (select `id` from `nuss_order` where `id` = new.id);  
  set d = (select `date` from `nuss_order` where `date` = new.date);  
if (a>=100) then  
  if(a>=1000) then  
    set b = 'BX' + d + cast(a as varchar);  
  else  
    b = 'BX' + d + concat('0',cast(a as varchar));  
  end if;  
else  
  if(a>=10) then  
    b = 'BX' + d + concat('00',cast(a as varchar));  
  else  
   b = 'BX' + d + concat('000',cast(a as varchar));  
  end if;  
end if;  
set new.oid = b;  
end  

我无法找到错误,如果有人能帮助我,那将是非常好的。感谢

0 个答案:

没有答案