当我尝试创建如下所示的触发器时,
CREATE TRIGGER FiscalYearTable1_bi
BEFORE INSERT
ON FiscalYearTable1
FOR EACH ROW
IF (
( EXTRACT (YEAR FROM FiscalYearTable1.start_date) != FiscalYearTable1.fiscal_year - 1) OR
(EXTRACT (MONTH FROM FiscalYearTable1.start_date) != 04) OR
(EXTRACT (DAY FROM FiscalYearTable1.start_date) != 01)
)
SET FiscalYearTable1.fiscal_year = 1/0;
我收到以下错误,
错误1064(42000):您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在'FROM FiscalYearTable1.start_date'附近使用正确的语法!= FiscalYearTable1.fiscal_year - 1)或(第1行的EXTRA'
我无法弄清楚错误是什么。有任何想法吗?感谢
答案 0 :(得分:0)
类似的东西:
delimiter #
create trigger FiscalYearTable1_before_ins_trig before insert on FiscalYearTable1
for each row
begin
declare y smallint unsigned default 0;
declare m tinyint unsigned default 0;
declare d tinyint unsigned default 0;
set y = year(new.start_date);
set m = month(new.start_date);
set d = day(new.start_date);
-- whatever logic you require...
if y != new.fiscal_year-1 or m != 4 or d != 1 then
set new.fiscal_year = null;
end if;
end#
delimiter ;