我已经在Oracle SQL中学习了触发器,而在MySQL中却不是那么精通。我试图将触发器命令从Oracle转换为MySQL。首先,我找不到when
语句,而是找到了if else
。这是我写的:
create trigger overdraft
after update on account
for each row
begin
if account.balance < 0 then
insert into borrower(select customer_name, account_number from depositor where new.account_number=depositor.account_number);
insert into loan(select new.account_number, new.branch_name, new.balance);
update account set balance = 0 where account.account_number = new.account_number;
end if;
end;
但是我遇到了三个语法错误,首先在左括号的第一个插入语句的末尾说:“语句不完整,期望是:','”。 end
的每一个上都有另外两个在说“结束在此位置无效:期望BEGIN,EOF,....”。我的代码有什么问题?我很难弄清楚。
像这样简单地使用Delimiter
DELIMItER //
create trigger overdraft
after update on account
for each row
begin
if account.balance < 0 then
insert into borrower(select customer_name, account_number from depositor
where new.account_number=depositor.account_number);
insert into loan(select new.account_number, new.branch_name, new.balance);
update account set balance = 0
where account.account_number = new.account_number;
end if;
end;
DELIMItER ;