创建触发器时MySql ERROR 1064(4200)

时间:2014-05-18 07:50:11

标签: mysql triggers

这是我编写的用于创建触发器的mysql查询。当我使用MySql工作台执行此查询时,它可以完美地执行。但是当我尝试使用MySQL 5.6 Command Line Client执行它时,

它给出了ERROR 1064(4200)“检查与你的MySql服务器版本相对应的手册,以便在'声明L_S_date日期附近使用;声明N_S_date日期;声明no_months int;在第1行声明gen;”。

任何人都可以帮我解决这个问题。

 DROP TRIGGER IF EXISTS change_next_S_in_edit;
 DELIMITER $$
create trigger change_next_S_in_edit after update on job
for each row
begin
declare j_type varchar(30);
declare L_S_date date;
declare N_S_date date;
declare no_months int;
declare gen_SN varchar(800);
set @j_type=NEW.job_type;

if(NEW.job_type='Service')
then
    if(not exists(select * from Job where serial_no=new.serial_no and date>new.date and job_type='Service'))
    then
        select no_moths_for_service into @no_months from Sys_figures;
        set @L_S_date=NEW.date;
        set @gen_SN=NEW.serial_no;
        update Gen_Next_Service_Day 
        set Last_Ser_Date=NEW.date,Next_Ser_Date=ADDDATE(NEW.date,Interval @no_months Month) 
        where serial_no=@gen_SN;
    else
        select no_moths_for_service into @no_months from Sys_figures;
        select max(date) into @L_S_dat from Job where serial_no=new.serial_no and job_type='Service'; 
        set @gen_SN=NEW.serial_no;
        update Gen_Next_Service_Day 
        set Last_Ser_Date=@L_S_dat,Next_Ser_Date=ADDDATE(@L_S_dat,Interval @no_months Month) 
        where serial_no=@gen_SN;
    end if;
end if;
 end$$

 DELIMITER ;

0 个答案:

没有答案